If statements in different labels

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
bahiahanna
Newbie
Posts: 2
Joined: Tue Sep 11, 2018 12:54 am
Contact:

If statements in different labels

#1 Post by bahiahanna »

Uh, so hey. I have been having issues with this certain topic. Every time I do something like this it would have give me a exception error. I dunno what is wrong with it, or is there a another way to do this. To cut it short, I was planning to do a VN that has 3 stories in it, for example, A, B and C. If you choose A, you'll get some info about something. Once done, you'll be left with B and C. If you choose one of them, you have to bring your previous info to that story. Usually, it would work. But, let's say you want to choose B first, right? Label B requires the if info == True statement which you would get in Label A, but since you didn't choose story A at all, you didn't have the info true in the first place, so that's why there is a else option. But this is where the game gets an error, saying that name "info" is not defined, even though it is defined in Label A. And this is where I need help. Here is an example:

Code: Select all

label start:    
    $ story1 = False
    $ story2 = False
    
label menu1:
    
menu:
    "Story 1" if story1 == False:
        $ story1 = True
        jump story1
    "Story 2" if story2 == False:
        $ story2 = True
        jump story2
label story1:
    $knowledge = False
    "Hi, did you know what happened last night"
menu:
    "Yes":
        $knowledge = True
        "The thunderstorm stormed, right?"
        "Yes"
        jump menu1 
    "No":
        "It's best that you don't know"
        jump menu1
label story2:
    "What happened last night, I kinda have forgotten"
menu:
    "I don't know, sorry":
        "It's OK"
        return
    "A thunderstorm stormed harshly yesterday" if knowledge == True:
        "Ah, yes. I have finally remembered, thank you so much!"
        return
Would be gladly appreciated if anybody could help. Even if you couldn't help, thanks for taking your time to read my non-worthy issues :)

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If statements in different labels

#2 Post by trooper6 »

All variables must first be initialized outside of any block using default (if the variables will change their value) or define (if they will never change their values).

So...

Code: Select all


default story1 = False
default story2 = False
default knowledge = False

label start:        
    menu menu1:
        "Story 1" if story1 == False:
            $ story1 = True
            jump story1
        "Story 2" if story2 == False:
            $ story2 = True
            jump story2
            
label story1:
    menu:
        "Hi, did you know what happened last night?"
        "Yes":
            $knowledge = True
            "The thunderstorm stormed, right?"
            "Yes"
            jump menu1 
        "No":
            "It's best that you don't know"
            jump menu1
            
label story2:
    menu:
        "What happened last night, I kinda have forgotten."
        "I don't know, sorry":
            "It's OK"
            return
        "A thunderstorm stormed harshly yesterday" if knowledge == True:
            "Ah, yes. I have finally remembered, thank you so much!"
            return
Also I'll note in your post you say you have a problem with "info" not being defined when you defined it in story1...but you don't define info in story1, you define knowledge in story1.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

bahiahanna
Newbie
Posts: 2
Joined: Tue Sep 11, 2018 12:54 am
Contact:

Re: If statements in different labels

#3 Post by bahiahanna »

Actually, the "info" not being defined was the VN i was working on. This was just an example. Wow, Thank you so much! It actually worked. Really appreciated!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]