Defining 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
dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Defining Statements

#1 Post by dIgItayel »

Hi guys~
This is a follow up on my post about expected statements. I'm still having the same problem, but this time, instead of an expected statement error, I get an error saying that a statement is undefined.

Error Message:

Code: Select all

While running game code:
  File "game/script.rpy", line 190, in script
    menu:
  File "game/script.rpy", line 211, in <module>
    "Are you his guardian?" if spirit == True:
NameError: name 'spirit' is not defined
Where I think I defined "spirit"

Code: Select all

"Are you a spirit?":
            $ spirit = True
            "So, Sera...You're a spirit, right?"
            
            jump spirit_sera
(This is part of a menu by the way)

The menu where the error occurs:

Code: Select all

  menu:
        "What do you want to talk about?"
        
        "Where do you guys live?":
            pn "So do you guys live close to the campus?"
            s "Oh! We live together, actually. We're roommates! We live about a mile off campus in this little rental house."
            n "Living with Sera is actually awful. Please save me."
            s "Oh shut up, you know you looooove me!"
            n "A-As if!"
            jump finding_out
            
        "Are you two dating?":
            pn "So, uh, are you two...dating?"
            n "W-WHAAAAT?!"
            s "Nonononononono! We're not dating!"
            n "E-Ew. No."
            s "Besides, I'm like, the most gay person ever. Like, ever. Feel free to call me the Ultimate Gay. And Naois here is about as straight as a circle."
            n "S-Sera!"
            s "Oh, I'm sorrrrrry. You're sensitive~ Hehehe"
            jump finding_out
            
        "Are you his guardian?" if spirit == True:
            pn "Are you Naois' Guardian?"
            jump naois_guardian
Any help is appreciated :)

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

Re: Defining Statements

#2 Post by SuperbowserX »

If it's part of a menu, then it's possible that line of code will never have ran by the time you get to that evaluation.

So what you should do is set that variable to false at the top of your script. That way, even if you never got to that point where it was true, it will still be defined.

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Defining Statements

#3 Post by dIgItayel »

SuperbowserX wrote:If it's part of a menu, then it's possible that line of code will never have ran by the time you get to that evaluation.

So what you should do is set that variable to false at the top of your script. That way, even if you never got to that point where it was true, it will still be defined.
So at the top I'd just put spirit = false? Or is it something else?

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

Re: Defining Statements

#4 Post by SuperbowserX »

Right after your start label, put in this line of code:

Code: Select all

$ spirit = False
That way, the variable you are evaluating will not be undefined in the event that it never becomes true.

dIgItayel
Regular
Posts: 32
Joined: Fri Mar 24, 2017 10:27 am
Contact:

Re: Defining Statements

#5 Post by dIgItayel »

SuperbowserX wrote:Right after your start label, put in this line of code:

Code: Select all

$ spirit = False
That way, the variable you are evaluating will not be undefined in the event that it never becomes true.
I still got this error:

Code: Select all

While running game code:
  File "game/script.rpy", line 191, in script
    menu:
  File "game/script.rpy", line 212, in <module>
    "Are you his guardian?" if spirit == True:
NameError: name 'spirit' is not defined

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

Re: Defining Statements

#6 Post by SuperbowserX »

change

Code: Select all

"Are you his guardian?" if spirit == True:
to

Code: Select all

"Are you his guardian?" if spirit:
(ignore this next sentence if you're not programming familiar) You don't need that operator for boolean evaluations. Simply saying if boolean is basically telling it "if this boolean is true".

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: Defining Statements

#7 Post by trooper6 »

Also best practices is to define your variables using the default statement outside of a block. Like so:

Code: Select all

default spirit = False

label start:
    "Blah blah"
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

Post Reply

Who is online

Users browsing this forum: tim640