[SOLVED] If statement in menu??

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Swein
Newbie
Posts: 20
Joined: Mon May 02, 2022 9:39 am
Contact:

[SOLVED] If statement in menu??

#1 Post by Swein » Fri Oct 14, 2022 3:31 pm

Code: Select all

label try:
    default option2 = True
    menu tavern1:
        if option2:
            s "I guess you're new around here, what do you want to do?"
        else:
            s "Ok, now what do you want to do?"
        "I want to find a job":
            $ gift = "job"
            "I'll search a job for you!"
        "I want to find a witch contract" if option2:
            $ option2 = False
            "Oh god sake! I never ever interest this things, they're haunted."
            jump tavern1
What I want to do is change the sentence the character says below when the menu options again appear after "jump". However, I couldn't do it.
Last edited by Swein on Sat Oct 15, 2022 6:35 am, edited 1 time in total.

User avatar
Tess
Newbie
Posts: 23
Joined: Thu Aug 04, 2022 3:43 pm
Projects: The Songbird Guild
Organization: Yurisoft
Github: wainwt2
Discord: Tess#7782
Contact:

Re: If statement in menu??

#2 Post by Tess » Fri Oct 14, 2022 8:39 pm

A little clunky I'll admit, but I think this'll work.

Code: Select all

default option2 = True #Can be defined anywhere, just make sure it comes before the try label

label try:
	$question = "I guess you're new around here, what do you want to do?" if option2 else "Ok, now what do you want to do?"
	menu tavern1:
        	"[question]"
        	"I want to find a job":
            		$ gift = "job"
            		"I'll search a job for you!"
        	"I want to find a witch contract" if option2:
        		$ option2 = False
            		"Oh god sake! I never ever interest this things, they're haunted."
            		jump try #Jump to the try label instead of jumping to the tavern1 menu statement so we hit our question assembly again

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: If statement in menu??

#3 Post by _ticlock_ » Fri Oct 14, 2022 10:28 pm

Swein wrote:
Fri Oct 14, 2022 3:31 pm
What I want to do is change the sentence the character says below when the menu options again appear after "jump". However, I couldn't do it.
if statements does not work this way in the choice menu.

I suggest to put if statement before the choice menu and then use extend expression in the choice menu. Also, add no-wait tag nw at the end, it will dismiss current say statement and you go straight to the choice menu with the correct question.

Code: Select all

default option2 = True

label try:

label tavern1:
    if option2:
        s "I guess you're new around here, what do you want to do?{nw}"
    else:
        s "Ok, now what do you want to do?{nw}"
    menu:
        extend ""
        "I want to find a job":
            $ gift = "job"
            "I'll search a job for you!"
        "I want to find a witch contract" if option2:
            $ option2 = False
            "Oh god sake! I never ever interest this things, they're haunted."
            jump tavern1

User avatar
Swein
Newbie
Posts: 20
Joined: Mon May 02, 2022 9:39 am
Contact:

Re: If statement in menu??

#4 Post by Swein » Sat Oct 15, 2022 6:33 am

_ticlock_ wrote:
Fri Oct 14, 2022 10:28 pm
Swein wrote:
Fri Oct 14, 2022 3:31 pm
What I want to do is change the sentence the character says below when the menu options again appear after "jump". However, I couldn't do it.
if statements does not work this way in the choice menu.

I suggest to put if statement before the choice menu and then use extend expression in the choice menu. Also, add no-wait tag nw at the end, it will dismiss current say statement and you go straight to the choice menu with the correct question.

Code: Select all

default option2 = True

label try:

label tavern1:
    if option2:
        s "I guess you're new around here, what do you want to do?{nw}"
    else:
        s "Ok, now what do you want to do?{nw}"
    menu:
        extend ""
        "I want to find a job":
            $ gift = "job"
            "I'll search a job for you!"
        "I want to find a witch contract" if option2:
            $ option2 = False
            "Oh god sake! I never ever interest this things, they're haunted."
            jump tavern1
You are my super hero, thanks! :) :)

User avatar
Swein
Newbie
Posts: 20
Joined: Mon May 02, 2022 9:39 am
Contact:

Re: If statement in menu??

#5 Post by Swein » Sat Oct 15, 2022 7:50 am

Tess wrote:
Fri Oct 14, 2022 8:39 pm
A little clunky I'll admit, but I think this'll work.

Code: Select all

default option2 = True #Can be defined anywhere, just make sure it comes before the try label

label try:
	$question = "I guess you're new around here, what do you want to do?" if option2 else "Ok, now what do you want to do?"
	menu tavern1:
        	"[question]"
        	"I want to find a job":
            		$ gift = "job"
            		"I'll search a job for you!"
        	"I want to find a witch contract" if option2:
        		$ option2 = False
            		"Oh god sake! I never ever interest this things, they're haunted."
            		jump try #Jump to the try label instead of jumping to the tavern1 menu statement so we hit our question assembly again
I just saw that, works too, and the extend method also works. Thank you. I appreciate that! Renpy won't die as long as there are people like you

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Dark12ose, Majestic-12 [Bot]