[SOLVED] Menu Choice if Statements

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
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

[SOLVED] Menu Choice if Statements

#1 Post by sasquatchii »

I am currently working on a game where the user has to read through all 4 menu choices before they can move on to the next bit of the game.

With the code I currently have though, the user is able to go through all 4 menu options, but once they click on the last option, they just cycle through the text of the last option indefinitely. How can I change the code so that, after they get through all 4 options, they are taken to the next menu (menu_think)? Here is what I have so far:

Code: Select all

# The game starts here.
label start:
    
    stop music fadeout 1.1
    
    scene bg darkpurple with dissolve


label choices:

menu choices:
    laika "[choices_text]"
    "Smell" if smell_action_done == False:
        $ smell_action_done = True
        $ choices_text = "What should I do now?"
        jump smell_action
    "Look" if look_action_done == False:
        $ look_action_done = True
        $ choices_text = "What should I do now?"
        jump look_action
    "Feel" if feel_action_done == False:
        $ feel_action_done = True
        $ choices_text = "What should I do now?"
        jump feel_action
    "Move" if move_action_done == False:
        $ move_action_done = True
        $ choices_text = "What should I do now?"
        jump move_action

label smell_action:
        laikas "This place smells mostly like me."
        laikasc "When the big noise happened, I was scared. {p}I relieved myself, but not on purpose."
        laikas "I can still smell where I piddled, but I don't think it matters right now..."
        laikas "I also smell myself. I smell like rotting fish."
        laikasc "It's hot in here and I don't feel so good. {p}I've been panting ever since the big noise."
        jump choices
    
label look_action:
        laika "It's pitch black. I can't see anything"
        laikasc "I can't look behind me or even turn around. {p}But I don't think there's anyone here."
        jump choices
    
label feel_action:
        laika "The room smells mostly like me."
        jump choices    
    
label move_action:
        laika "The room smells mostly like me."
        jump choices 


jump think

menu think:
    
    "Home":
        jump home
    "The trip out":
        jump trip
    "The Big Noise":
        jump noise
        
label home:
laikas "I should think about something else..."

label trip:
laikas "I should think about something else..."

label noise:
laikas "I should think about something else..."
Any help or advice is always appreciated!
Last edited by sasquatchii on Sun Jan 08, 2017 11:11 pm, edited 1 time in total.
ImageImage

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: Menu Choice if Statements

#2 Post by SuperbowserX »

Multiple ways to do this but I'd recommend you try to use an incrementing variable.

Before you reach "label choices", create a variable (can be called counter or whatever) that, at the end of each of those choices, will increment by one.

So it's something like this:

Code: Select all

if (counter != 4):
    menu choices:
        [...]
else:
    jump think
!= means "not equal to" by the way.

Each time you inititate one of those choices, increment the counter by 1. So when you first arrive at choices it'll be at 0. Second time one, and so on by the fifth time (at which you'll have seen all the choices) it'll be 4 and you can move on.

User avatar
Tempus
Miko-Class Veteran
Posts: 519
Joined: Sat Feb 16, 2013 3:37 am
Completed: Ladykiller in a Bind
Projects: StoryDevs
Tumblr: jakebowkett
Deviantart: jakebowkett
Github: jakebowkett
Location: Australia
Contact:

Re: Menu Choice if Statements

#3 Post by Tempus »

Okay, I don't know why I'm in this forum since I haven't used Ren'Py properly in like 2 years! So that's my disclaimer.

Onto your question! Firstly, in Python (and many other programming languages) when you want to check if something is True or False you can actually write it like this:

Code: Select all

# This is equivalent to "if smell_action_done == True:"
if smell_action_done:
    # stuff to do if smell_action_done is True
And if you want to see if it's False you can do this:

Code: Select all

# This is equivalent to "if smell_action_done == False:"
if not smell_action_done:
    # stuff to do if smell_action_done is False
Okay this time I'm actually onto your question! When you make a menu and give it a name like this:

Code: Select all

menu choices:
    "choice_1"
        jump thing_1
    "choice_2"
        jump thing_2
    "choice_3"
        jump thing_3
It's the same as writing this:

Code: Select all

label choices:
    menu:
        "choice_1"
            jump thing_1
        "choice_2"
            jump thing_2
        "choice_3"
            jump thing_3
Basically, giving a menu a name makes it into a label you can jump to. In the code you shared there's a label before your menu with the same name as the menu. I don't know whether Ren'Py cares about it, but we'll need to avoid that shorthand to get your code to do what you want it to.

Here's how I'd re-write your code so that you skip to the second menu once you've seen all four choices:

Code: Select all

# The game starts here.
label start:
    stop music fadeout 1.1
    scene bg darkpurple with dissolve

# this label is what's being jumped to which means we can
# check some stuff prior to bringing up the menu
label choices:
    
    # this checks to see if *all* actions are done. If they are, jump to the think menu instead
    if smell_action_done and look_action_done and feel_action_done and move_action_done:
        jump think

    # by default I've made choices_text just an empty string
    $ choices_text = ""

    # but if any of the actions have been done before we'll change it to "What should I do now?" --
    # this way we don't need to set it inside of every choice, which makes it easier to change later
    if smell_action_done or look_action_done or feel_action_done or move_action_done:
        $ choices_text = "What should I do now?"

    # finally onto the menu! I've used "if not smell_action_done:" as I mentioned above -
    # again, it's just a shorthand for "if smell_action_done == False:"
    menu:
        laika "[choices_text]"
        "Smell" if not smell_action_done:
            $ smell_action_done = True
            jump smell_action
        "Look" if not look_action_done:
            $ look_action_done = True
            jump look_action
        "Feel" if not feel_action_done:
            $ feel_action_done = True
            jump feel_action
        "Move" if not move_action_done:
            $ move_action_done = True
            jump move_action

# the action labels below and their contents are the same, but they were originally indented with 8 spaces
# instead of 4. Labels only need to be indented with 4 spaces (I dunno what happens with 8!)
label smell_action:
    laikas "This place smells mostly like me."
    laikasc "When the big noise happened, I was scared. {p}I relieved myself, but not on purpose."
    laikas "I can still smell where I piddled, but I don't think it matters right now..."
    laikas "I also smell myself. I smell like rotting fish."
    laikasc "It's hot in here and I don't feel so good. {p}I've been panting ever since the big noise."
    jump choices
    
label look_action:
    laika "It's pitch black. I can't see anything"
    laikasc "I can't look behind me or even turn around. {p}But I don't think there's anyone here."
    jump choices
    
label feel_action:
    laika "The room smells mostly like me."
    jump choices    
    
label move_action:
    laika "The room smells mostly like me."
    jump choices 

# removed "jump think" from here

# left this menu with a name -- might as well make the menu it's own label
# as we don't need to check anything first this time
menu think:
    "Home":
        jump home
    "The trip out":
        jump trip
    "The Big Noise":
        jump noise
        
# this is the same but I've indented the text - anything that's supposed
# to be within a label must be indented
label home:
    laikas "I should think about something else..."

label trip:
    laikas "I should think about something else..."

label noise:
    laikas "I should think about something else..."
And I think that should work! Again I haven't used Ren'Py (or Python for that matter) in ages so hopefully I'm not leading you astray! Good luck with your project :)
StoryDevs — easy-to-search profiles for VN devs (under construction!)

User avatar
sasquatchii
Miko-Class Veteran
Posts: 552
Joined: Fri Jul 04, 2014 7:48 am
Completed: A Day in the Life of a Slice of Bread
Deviantart: sasquatchix
Soundcloud: sasquatchii
itch: sasquatchii
Location: South Carolina
Contact:

Re: [SOLVED] Menu Choice if Statements

#4 Post by sasquatchii »

Tempus, your solution worked perfectly!! Thank you so much (and thanks SuperbowserX for your thoughts as well)!
ImageImage

Post Reply

Who is online

Users browsing this forum: No registered users