Need help with if statments in my code.

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
Sakura02
Regular
Posts: 61
Joined: Fri Aug 27, 2010 7:49 pm
Projects: Ecchie Sketchy
Contact:

Need help with if statments in my code.

#1 Post by Sakura02 »

Ok so I have an image map which is a bulletin board with flyers on it that you can click on. I want it be so when you click on one, you get a menu item which asks if you want to confirm. However i keep getting errors with the if statements. Does thsi work or no

Code: Select all

elif result == "student":
    
    show melonsurprised with vpunch:
        xpos 150 ypos 50
        
    hide melonnya    
    
    m "Huh student council for serious! Fer serious? Who the heck would want to do that??!"
    
    menu:
        "Yes":
            jump Student_Club
        
        "No wait ":
            jump Bulletin_Board
    
elif result == "cook":
    
    show melontalking with dissolve:
        xpos 150 ypos 50
    
    m "Yah! You picked my club! Awesome are you sure?"        

    menu:
        "Yes":
            jump Cooking_Club
        
        "No wait ":
            jump Bulletin_Board
What did I miss? Thnx

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Need help with if statments in my code.

#2 Post by SusanTheCat »

Is that the whole snippet?

It should start with an if:

Code: Select all

if result == "student":
    [blah blah blah]
    
elif result == "cook":
    [blah blah blah]

[rest of code]
reference:
http://www.renpy.org/wiki/renpy/doc/ref ... _Statement

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Need help with if statments in my code.

#3 Post by SusanTheCat »

Is that the whole snippet?

It should start with an if:

Code: Select all

if result == "student":
    [blah blah blah]
    
elif result == "cook":
    [blah blah blah]

[rest of code]
reference:
http://www.renpy.org/wiki/renpy/doc/ref ... _Statement

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

Sakura02
Regular
Posts: 61
Joined: Fri Aug 27, 2010 7:49 pm
Projects: Ecchie Sketchy
Contact:

Re: Need help with if statments in my code.

#4 Post by Sakura02 »

Thanks for the quick response. Yeah I do have an if statement at the beginning...sorry that was the ending. So what is the difference between 'if' and 'elif' ??

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Need help with if statments in my code.

#5 Post by Aleema »

elif means "else if", so if the statement above it isn't true, then continue down the line until something is true.

If you want multiple things to appear if enabled, they need to all be Ifs and not Else Ifs. Because "elif" basically means "or".

Please post your errors next time, so we can find out what you're doing wrong.

Sakura02
Regular
Posts: 61
Joined: Fri Aug 27, 2010 7:49 pm
Projects: Ecchie Sketchy
Contact:

Re: Need help with if statments in my code.

#6 Post by Sakura02 »

YES it works :D Thanks. Sorry next time I'll post the whole error ^_^ I was confused about if and else statements, it's my first time using them.

Post Reply

Who is online

Users browsing this forum: No registered users