Page 1 of 1

Error when Creating Flags - Help

Posted: Thu Jan 05, 2017 3:55 am
by exax
I am currently writing a Visual Novel and need to establish a fair number of flags.
However, I am having trouble recalling the flags.

In the first script
label note_2:
if note1 == "no_go":
$ hano_flag_1 = True
jump note2_home
In a later script
menu:
"Hano" if hano_flag_1 == True:
$ hano_flag_2 = True
jump note4_afternoon


Error
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/scripts/note_4.rpy", line 322, in script
menu:
File "game/scripts/note_4.rpy", line 328, in <module>
"Hano" if hano_flag_1 == True:
NameError: name 'hano_flag_1' is not defined

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

Full traceback:
File "game/scripts/note_4.rpy", line 322, in script
menu:
File "C:\Program Files\renpy\renpy-6.99.4-sdk\renpy\ast.py", line 1411, in execute
choice = renpy.exports.menu(choices, self.set)
File "C:\Program Files\renpy\renpy-6.99.4-sdk\renpy\exports.py", line 714, in menu
if renpy.python.py_eval(condition) ]
File "C:\Program Files\renpy\renpy-6.99.4-sdk\renpy\python.py", line 1482, in py_eval
return eval(py_compile(source, 'eval'), globals, locals)
File "game/scripts/note_4.rpy", line 328, in <module>
"Hano" if hano_flag_1 == True:
NameError: name 'hano_flag_1' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.4.467
TRUMPET 1.2 0.0

Note
- The same error occurs when I tried to use $ flag = "Yes" or other alternatives names
- The same error occurs when the ($ X = True ) statement and (if X == True) statement in the same script file
- The same error occurs when the ($ X = "Y" ) statement and (if X == "Y") statement in the same script file


Please help me identify the problem >___<

Re: Error when Creating Flags - Help

Posted: Thu Jan 05, 2017 3:56 am
by exax
Note: The indentation is not showing in the quotes, but the script is properly indented

Re: Error when Creating Flags - Help

Posted: Thu Jan 05, 2017 4:05 am
by Ocelot
Use code tage, not quote tag.

What do you think would happen if somebody will not hit the line setting variable to True? What would be the value of the variable in this case?

You need to make sure that variable always has some value assigned to it. Easiest way do do so is to give it a default value:

Code: Select all

# Outside of any context, even init statements
default hano_flag_1 = False

Re: Error when Creating Flags - Help

Posted: Thu Jan 05, 2017 6:00 pm
by exax
Ocelot wrote:Use code tage, not quote tag.

What do you think would happen if somebody will not hit the line setting variable to True? What would be the value of the variable in this case?

You need to make sure that variable always has some value assigned to it. Easiest way do do so is to give it a default value:

Code: Select all

# Outside of any context, even init statements
default hano_flag_1 = False
!!! I forgot about the False value !!!
Thank you so much !