if statement help

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
fishtank
Newbie
Posts: 8
Joined: Wed Aug 30, 2023 12:51 am
Contact:

if statement help

#1 Post by fishtank »

Maybe I am doin this completely wrong, but I thought I followed the documentation correctly on how to do "if/elif/else" statements.

Here is what I am trying to do. I want checks done, before an action can be completed. Only if the stats allow. Is it spacing or am I completely messing this up?

Code: Select all

    menu:
        "Try the front door of the store?":
            if pick == True:
                if sneak >= 10:
                    jump store_breakin
                else:
                    jump more_skills
        "Maybe I can find an open window.":
            if wopen== True:
                if sneak >= 8:
                    jump store_breakin_window
                else:
                    jump more_skills
            elif sneak >= 6:
                if wopen == false:
                    if crowbar == True:
                        jump store_break_in_window2           
                    else:
                        jump more_skills
        "I should go home":
            jump front_home
Menus all work fine, but it's not checking for the variable. They are defined. Even if I change the True one's to False and the False to True and the stats
from 0 to 10 and vise versa, it still only takes the first if in each option, whether the items/skill are present or not.

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: if statement help

#2 Post by plastiekk »

fishtank wrote: Thu Sep 14, 2023 9:43 pm ...
Your line indentation is not correct, if I am not mistaken.
Try it like this:

Code: Select all

    menu:
        "Try the front door of the store?":
            if pick:                        # the same like if pick == True
                if sneak >= 10:
                    jump store_breakin
            else:                           # does a jump, if pick == False, to label more_skills
                jump more_skills
        ...
        
Why on earth did I put the bread in the fridge?

User avatar
plastiekk
Regular
Posts: 112
Joined: Wed Sep 29, 2021 4:08 am
Contact:

Re: if statement help

#3 Post by plastiekk »

fishtank wrote: Thu Sep 14, 2023 9:43 pm ...
Your line indentation is not correct, if I am not mistaken.

Edit: Wait, what is if pick is False and sneak < 10?
I would not show this selection at all if the conditions are not met.
like:

Code: Select all

menu:
    "Try the front door of the store?" if pick is True and sneak >=10:
        jump store_breakin
    ...
    
Edit2: I don't know what my browser is doing, I click edit post and a new post is created after submitting it.
Why on earth did I put the bread in the fridge?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: if statement help

#4 Post by Imperf3kt »

I would make some slight adjustments.

Code: Select all

    menu:
        "Try the front door of the store?":
            if pick: #== True is not needed here. '== True' essentially says if True is True
                if sneak >= 10:
                    jump store_breakin
                else:
                    jump more_skills
        "Maybe I can find an open window.":
            if wopen:
                if sneak >= 8:
                    jump store_breakin_window
                else:
                    jump more_skills
            elif sneak >= 6:
                if not wopen: # same reasoning as with 'True' above
                    if crowbar:
                        jump store_break_in_window2           
                    else:
                        jump more_skills
        "I should go home":
            jump front_home
As to why it doesn't work, we would need to see more of what is going on. What happens at label 'more_skills', for example. Do you loop back to this menu?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

fishtank
Newbie
Posts: 8
Joined: Wed Aug 30, 2023 12:51 am
Contact:

Re: if statement help

#5 Post by fishtank »

plastiekk wrote: Fri Sep 15, 2023 3:32 am
fishtank wrote: Thu Sep 14, 2023 9:43 pm
Your line indentation is not correct, if I am not mistaken.
...
Well that wouldn't be indentation then, more of an incorrect statement right?
plastiekk wrote: Fri Sep 15, 2023 4:02 am
fishtank wrote: Thu Sep 14, 2023 9:43 pm
...
Edit: Wait, what is if pick is False and sneak < 10?
I would not show this selection at all if the conditions are not met.
That is what the other selections are for, if they are not met. But I need that check for that part of the story.
Imperf3kt wrote: Sat Sep 16, 2023 3:40 am I would make some slight adjustments.
As to why it doesn't work, we would need to see more of what is going on. What happens at label 'more_skills', for example. Do you loop back to this menu?
I see what you are saying. It just needs to check to see if the player has the item and doesn't need to check the flag True/False, as the item will either be there or not. I'll check that out.
"More_skills" just tells the player they lack sufficient skills to open the door. By this point, they should be aware of their stats. There is a stat page they can check as well. That label just tells them they need more skills, an explanation of how to obtain and see their stats, and what skill is needed. I have a few "more_skills" labels, one for each stat, as to not confuse the player of which stat they need. i.e. "more_skills" = sneak, "more_skills2" =charisma. etc. etc.

Thank you all for the input. I will give them a go tonight. Sorry, for the late response. Late nights at work.

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot]