NameError: name is not defined [solved]

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
ibukichan
Regular
Posts: 102
Joined: Tue May 20, 2014 2:24 am
Completed: Project E.A.R.T.H. [NaNo '15]
Projects: A Step Ahead, Deadhead, Jinsei no Mondai
Skype: aikosakana
itch: aikosakana
Location: Canada
Contact:

NameError: name is not defined [solved]

#1 Post by ibukichan » Wed Mar 25, 2015 4:15 am

I'm not sure if I'm just bad at programming, but I've been struggling with this bit of code for a few hours, and I have no idea how to fix this.

Here's the code:

Code: Select all

label attempt_one:

    $ password = "example"

    $ attempt = renpy.input("Input the password.")
    
    if attempt == password:
        jump correct_password
        
    else:
        jump attempt_two
Here's the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 693, in script
    if attempt == password:
  File "game/script.rpy", line 693, in <module>
    if attempt == password:
NameError: name 'password' is not defined

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

Full traceback:
  File "game/script.rpy", line 693, in script
    if attempt == password:
  File "C:\Users\Owner\Desktop\Programs\renpy-6.17.6-sdk\renpy-6.17.6-sdk\renpy\ast.py", line 1587, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\Owner\Desktop\Programs\renpy-6.17.6-sdk\renpy-6.17.6-sdk\renpy\python.py", line 1416, in py_eval
    return eval(py_compile(source, 'eval'), globals, locals)
  File "game/script.rpy", line 693, in <module>
    if attempt == password:
NameError: name 'password' is not defined
Please help me sort this out, this is a vital part of my project.
Last edited by ibukichan on Wed Mar 25, 2015 5:17 am, edited 1 time in total.

rivvil
Regular
Posts: 26
Joined: Fri Feb 20, 2015 3:05 pm
Location: Russia
Contact:

Re: NameError: name is not defined

#2 Post by rivvil » Wed Mar 25, 2015 5:03 am

This code snippet works for me smoothly. Have you tried to test it in a newly created game?
Note althought that my Ren'Py version is 6.18.3.

User avatar
ibukichan
Regular
Posts: 102
Joined: Tue May 20, 2014 2:24 am
Completed: Project E.A.R.T.H. [NaNo '15]
Projects: A Step Ahead, Deadhead, Jinsei no Mondai
Skype: aikosakana
itch: aikosakana
Location: Canada
Contact:

Re: NameError: name is not defined

#3 Post by ibukichan » Wed Mar 25, 2015 5:17 am

Huh. And now it's working. Guess I just needed to re-open the game. Thank you for your time, although I feel like I wasted it. >_<

User avatar
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Re: NameError: name is not defined [solved]

#4 Post by Queex » Wed Mar 25, 2015 5:53 am

Yeah, ren'py reloads scripts and resources and tries to carry on from the previous position, but it doesn't always do so perfectly. For example, if you added the line that defined 'password', then reloaded, then the variable would not be set because it wasn't in the array of stored values before the reload, and you were past that line when the 'save' was reloaded with the new code.

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_