variable defined but renpy complains of 'name not defined'

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
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

variable defined but renpy complains of 'name not defined'

#1 Post by korova »

Here is a piece of code that generates an error

Code: Select all

default open_stairs_mainhall_door = False ## par defaut, la porte de la stairs room est fermée

## Définition des vues génériques
image stairsgf entrance = ConditionSwitch(
    "from_room == 'mainhall'","stairsgf frommainhall",
    open_stairs_mainhall_door,"stairsgf fromtvlounge open",
    True,"stairsgf fromtvlounge closed"
    )
Ren'py complains like that

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/stairs_groundfloor.rpy", line 19, in script
    image stairsgf entrance = ConditionSwitch(
  File "game/stairs_groundfloor.rpy", line 21, in <module>
    open_stairs_mainhall_door,"stairsgf fromtvlounge open",
NameError: name 'open_stairs_mainhall_door' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/stairs_groundfloor.rpy", line 19, in script
    image stairsgf entrance = ConditionSwitch(
  File "/usr/share/games/renpy/renpy/ast.py", line 942, in execute
    img = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "/usr/share/games/renpy/renpy/python.py", line 1836, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/stairs_groundfloor.rpy", line 21, in <module>
    open_stairs_mainhall_door,"stairsgf fromtvlounge open",
NameError: name 'open_stairs_mainhall_door' is not defined

Linux-4.14.0-3-amd64-x86_64-with-debian-buster-sid
Ren'Py 6.99.14.1.3218
The House 0.1
Sat Mar 24 18:57:24 2018
I don't understand why ren'py complains as 'open_stairs_mainhall_door' is defined just above the ConditionSwitch.

I can't change the "default' for "define" as the value of 'open_stairs_mainhall_door' will change during the game. (I also tried to put open_stairs_mainhall_door between quotes, same error message)

I'm kind of stuck here

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: variable defined but renpy complains of 'name not defined'

#2 Post by Ocelot »

You have forgot quotes around open_stairs_mainhall_door
< < insert Rick Cook quote here > >

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: variable defined but renpy complains of 'name not defined'

#3 Post by korova »

Ocelot wrote: Sat Mar 24, 2018 2:16 pm You have forgot quotes around open_stairs_mainhall_door
You were right, though I had tried that
korova wrote: Sat Mar 24, 2018 2:04 pm (I also tried to put open_stairs_mainhall_door between quotes, same error message)
BUT
I changed only the first ConditionSwitch, and forgot that I had two more after, with the same condition used :facepalm:
So, of course, error happened again.

Once I changed the 3 ConditionSwitch, works like a charm.

This quote thing is a little confusing though...

Thanks Ocelot !

Post Reply

Who is online

Users browsing this forum: No registered users