Using an if statement within an if statement?

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
ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Using an if statement within an if statement?

#1 Post by ShadowBoxGames » Wed Nov 09, 2016 6:42 pm

Hello everyone, I'm new to renpy and am using the gui interface for my game in progress.
I wanted to create a cell phone mechanic in my game for the player to ask characters out on dates. The way I set it up is by using an imagemap since it seemed the best way.

However, I ran into trouble when coding the results of each option because I tried to use conditional statements within a conditional statement. Renpy won't work, claiming there is an indentation mismatch, but it seems no matter how I rearrange the indentation nothin works? Is there something else I'm missing here or is it really just a big screw up in indentation?

Here's the current code:

Code: Select all

call screen phone_all_contacts

$ result = _return

if result == "alyssa":
    
    n "Hey alyssa do you wanna hang out?"

       if alyssa_points >= 250:
             
    al "Absolutely, Nadine! Where did you have in mind?"
        
    menu:
        "The library":
            jump library_date_alyssa
        "The park":
            jump park_date_alyssa
        "Ice cream parlor":
            jump scoops_date_alyssa
        "The arcade":
            jump arcade_date_alyssa
        "The mall":
            jump mall_date_alyssa 

         elif alyssa_points >=250: 
    al "Sorry, Nadine. I'm busy right now. Maybe next time."

elif result == "Henry":
    n "Hey, Henry, do you want to hang out?" 
the code goes on for a few more characters, but I haven't set up anything but 1 line of dialogue for them like shown for Henry.
Last edited by ShadowBoxGames on Mon Jun 11, 2018 11:32 pm, edited 2 times in total.

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Using an if statement within an if statement?

#2 Post by wyverngem » Wed Nov 09, 2016 6:47 pm

The alignment is really off. You need to align the if with each other to know what they're doing.

Code: Select all

    if result == "alyssa":        
        n "Hey alyssa do you wanna hang out?"
        if alyssa_points >= 250:
            al "Absolutely, Nadine! Where did you have in mind?"
            
            menu:
                "The library":
                    jump library_date_alyssa
                "The park":
                    jump park_date_alyssa
                "Ice cream parlor":
                    jump scoops_date_alyssa
                "The arcade":
                    jump arcade_date_alyssa
                "The mall":
                    jump mall_date_alyssa 
    
        elif alyssa_points >=250: 
            al "Sorry, Nadine. I'm busy right now. Maybe next time."
    
    elif result == "Henry":
        n "Hey, Henry, do you want to hang out?"
Also with the second if statement you're checking for the same condition.
<= Less than or equal
>= Greater than or equal

mard
Regular
Posts: 50
Joined: Thu Nov 03, 2016 3:38 am
Location: Standing right behind you.
Contact:

Re: Using an if statement within an if statement?

#3 Post by mard » Thu Nov 10, 2016 3:55 am

Something else to remember, as it'll trip you up as you get further in, is you want to close out a conditional statement with else, and not elif.

conditional statements are structured as

Code: Select all

if
elif
else
with else closing them out.
Tend to be a bit quiet, but will help where I can.

Enjoy the drinks folks.

ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Re: Using an if statement within an if statement?

#4 Post by ShadowBoxGames » Thu Nov 10, 2016 10:57 pm

wyverngem wrote:The alignment is really off. You need to align the if with each other to know what they're doing.

Code: Select all

    if result == "alyssa":        
        n "Hey alyssa do you wanna hang out?"
        if alyssa_points >= 250:
            al "Absolutely, Nadine! Where did you have in mind?"
            
            menu:
                "The library":
                    jump library_date_alyssa
                "The park":
                    jump park_date_alyssa
                "Ice cream parlor":
                    jump scoops_date_alyssa
                "The arcade":
                    jump arcade_date_alyssa
                "The mall":
                    jump mall_date_alyssa 
    
        elif alyssa_points >=250: 
            al "Sorry, Nadine. I'm busy right now. Maybe next time."
    
    elif result == "Henry":
        n "Hey, Henry, do you want to hang out?"
Also with the second if statement you're checking for the same condition.
<= Less than or equal
>= Greater than or equal
Okay, thank you so much. Yeah I meant to put in a < sign instead but must've mis-typed there.

ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Re: Using an if statement within an if statement?

#5 Post by ShadowBoxGames » Thu Nov 10, 2016 10:58 pm

mard wrote:Something else to remember, as it'll trip you up as you get further in, is you want to close out a conditional statement with else, and not elif.

conditional statements are structured as

Code: Select all

if
elif
else
with else closing them out.
Got it! Thank you so much!

Post Reply

Who is online

Users browsing this forum: _ticlock_