NameError: name is not defined after loading

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
Eva Kiss
Newbie
Posts: 5
Joined: Wed Apr 26, 2017 1:23 pm
Contact:

NameError: name is not defined after loading

#1 Post by Eva Kiss »

Please help, this is driving me crazy!

I use and "if == True" statement to show a line of text at one point in the game. The problem happens when I reach this point and the statemen is not "True". The game should just ignore the text and follow along.

The variable is set to "False" in a point on the script which is not missable depending on the choices you make during the game. You go thorugh this secene every single time.

If I play the game from the start or an early savegame, before the statement is set, when I reach this point everything goes smoothly. However, if I load from a save after the statement has been set to "False", it gives me the "NameError: name is not defined" error. The problem occurs when you don't pick the choice that sets the variable from "False" to "True", and the game tries to read the "if variable == True" statement.

I've tried setting a "default = False" at the start of the script, so the variable is always set even if the choices made on the game never sets it to "True".

I don't know how to fix this. As i said, if I play the game in one go the problem never shows up. Only when loading saves.

Can anyone help??

Eva Kiss
Newbie
Posts: 5
Joined: Wed Apr 26, 2017 1:23 pm
Contact:

Re: NameError: name is not defined after loading

#2 Post by Eva Kiss »

EDIT: If I load at the point were the variable is set, and I roll back, and progress ahead the problem does not show.

So, the problem seems to be, the variable resets after I load the game.

The thing is, this does not happen with all my variables. Some that I set long before still work fine. And i can't see any difference in the way I've set them.

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: NameError: name is not defined after loading

#3 Post by Divona »

It could be the compatible issue with the old save which save before the variable being set "default". Could you save the game now since you have define the variable with default value, and load to see if the issue still appears?
Completed:
Image

Eva Kiss
Newbie
Posts: 5
Joined: Wed Apr 26, 2017 1:23 pm
Contact:

Re: NameError: name is not defined after loading

#4 Post by Eva Kiss »

I'm fiddling with it. I deleted the default variables. I managed to make some of the faulty statements work, but I'm not sure how. I think maybe it has to do with the fact that the "True" status were being set under another "if" statement, even if the previous "False" statement were normally set. I made the "if" statements jump to a label and set the "True" status under them, and it seems to work...

However, I'm still struggling with another statement and this doesn't seem to be te problem with this one...

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: NameError: name is not defined after loading

#5 Post by trooper6 »

Um...what is the name of this variable? In the examples you've given...there is no variable name at all.

Code: Select all

default say_line1 = False

label start:
    menu:
        "Do you love me?"
        "Yes":
            $ say_line1 = True
        "No":
            $ say_line2 = False

    "Your love interest doesn't say anything in return, just nods."
    "You go on lots of adventures for thousands of words."
    "There is a moment of quiet."
    if say_line1:
       " The love interest tells you: I love you, too."
"The game is over."

That should work. If you are using code that looks like this and having strange save problems...then you should start a fresh new game and with a fresh new save.
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

Eva Kiss
Newbie
Posts: 5
Joined: Wed Apr 26, 2017 1:23 pm
Contact:

Re: NameError: name is not defined after loading

#6 Post by Eva Kiss »

Hey, I think the problem was precisely this. The old save could not find the variable for some reason. Beginning a new game, saving it and loading that file did not give me any problem. I suppose the save file could not update some of the information that was changed or something like that...
It seems to work now. I'll see if i can solve the problem this way if it presents itself again. Thanks guys!

Post Reply

Who is online

Users browsing this forum: Google [Bot]