Error says my variable isn't defined, but it appears to be

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
User avatar
anawfullotofcups
Newbie
Posts: 2
Joined: Mon May 13, 2019 12:25 pm
Projects: Nullity, a short sci-fi suspense story where the reader forms the protagonist's personality through dialogue choices
Contact:

Error says my variable isn't defined, but it appears to be

#1 Post by anawfullotofcups » Mon May 13, 2019 12:35 pm

In my visual novel, the reader will have some influence over the personality of the main character. To keep track of this, I am categorizing each dialogue choice answer as red, blue, or purple.
I am also keeping track of two other variables: whether the player lied when answering a specific question, and whether the player pissed off a character named Howe.
Below is what I have added right after my start label.
label start:

$ blue_points = 0
$ purple_points = 0
$ red_points = 0
$ c1choice3_lie = 0
$ howe_anger = 0
So far, I have had no problem with this. I have been able to add if statements referring to the number of each type of points the player has, and even the flag on whether the player lied ('c1choice3_lie') has functioned without issue.

However, when I added the howe_anger variable (the player will have many opportunities to piss Howe off and could possibly gather more than one point towards this), this is when problems began. Here is a snippet from my script, showing the menu in which the player has their first chance to make Howe mad:
menu:

"So I couldn't help but retort.":
$ red_points += 1
$ howe_anger += 1
jump howe1choice2_red
This is when I receive the error "NameError: name 'howe_anger' is not defined."
Since 'howe_anger' appears exactly in that fashion both at the beginning and in context, and none of the other point types has returned this error (the red point that is gained here goes off without a hitch when I remove the howe_anger point), I'm sort of at a loss. What have I done incorrectly here which is causing the error?

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Error says my variable isn't defined, but it appears to be

#2 Post by Alex » Mon May 13, 2019 2:31 pm

This might have happened if you've restored the game from save, made before 'howe_anger' variable was added into script.
That's why default statement is the best way to declare your variables - https://www.renpy.org/doc/html/python.h ... statement

User avatar
anawfullotofcups
Newbie
Posts: 2
Joined: Mon May 13, 2019 12:25 pm
Projects: Nullity, a short sci-fi suspense story where the reader forms the protagonist's personality through dialogue choices
Contact:

Re: Error says my variable isn't defined, but it appears to be

#3 Post by anawfullotofcups » Tue May 14, 2019 9:43 am

That did it! Thanks, this is my first shot at a Renpy project so I'm still learning stuff like this. I appreciate the help :)

rames44
Veteran
Posts: 232
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Error says my variable isn't defined, but it appears to be

#4 Post by rames44 » Tue May 14, 2019 12:08 pm

This is why the usual recommendation is to set up variables’ initial values with “default” rather than assigning them after the start label - it allows you to add new variables and have them work with old saves.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], span4ev