NameError: name is 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
TKana
Newbie
Posts: 2
Joined: Sat Sep 03, 2016 10:21 pm
Contact:

NameError: name is not defined

#1 Post by TKana » Sat Sep 03, 2016 10:34 pm

Hi there,

i've just started with renpy and I'm making some simple scripts to test what i want and how to use it.

After deleting my previous attempt, i've started with a new layout, keeping my variables in one file, my characters in another and so on. From what i've read ( and tested in my previous experiment) that should work.

Anyways, i have:
A .rpy file with my variables, which just contains :

Code: Select all

$ari_base = 0
and the main script file, which just contains :

Code: Select all

label start:
    ari "Welcome!"
    menu:
       "what do you want to do"
       "adding 1 stat":
                $ari_base += 1
                ari "check now"
                jump start
       "decrease 1 stat.":
                $ari_base -= 1
                ari "check now"
                jump start
       "stat value":
                ari "[ari_base]"
                jump start
Running this simple script gives me the following error:
I'm sorry, but an uncaught exception occurred.

Code: Select all

While running game code:
  File "game/script.rpy", line 10, in script
    $ari_base += 1
  File "game/script.rpy", line 10, in <module>
    $ari_base += 1
NameError: name 'ari_base' is not defined
I'm pretty sure this worked in my previous experiment, and im not sure why it doesnt work now. Any help?

Side note, how do i give the ari_base a minimum and maximum value? Tried the following:

Code: Select all

$ari_base =max(min(0, 10), 0)
This worked for max, but not for minimum.

Thanks in advance!

AXYPB
Regular
Posts: 95
Joined: Thu Sep 04, 2014 3:04 am
Github: AXYPB
Contact:

Re: NameError: name is not defined

#2 Post by AXYPB » Sat Sep 03, 2016 11:09 pm

Variables should be initialized in an init: block with the default statement.

Code: Select all

init:
    default ari_base = 0
To clamp your variable to a range of 0 to 10, this code should clamp to a maximum of 10 with min() then clamp to a minimum of 0 with max().

Code: Select all

$ ari_base = max(0,min(ari_base,10))
Last edited by AXYPB on Sun Sep 04, 2016 1:13 am, edited 1 time in total.

TKana
Newbie
Posts: 2
Joined: Sat Sep 03, 2016 10:21 pm
Contact:

Re: NameError: name is not defined

#3 Post by TKana » Sat Sep 03, 2016 11:32 pm

Thanks for the quick reply! I've edited the variables.rpy to the following:

Code: Select all

init:
    default ari_base = 0
$ ari_base = max(0,min(ari_base,10))
I no longer get the error (yay!) but the min and max dont seem to work. I'm pretty sure its $ ari_base = max(0,min(ari_base,10)) that i've placed wrong, but im not sure where i should put it.

Any tips or remarks?

User avatar
raeru
Regular
Posts: 28
Joined: Fri Jun 17, 2016 7:45 am
IRC Nick: ryle
Deviantart: ryle-chan
Location: Philippines
Contact:

Re: NameError: name is not defined

#4 Post by raeru » Thu Oct 06, 2016 1:14 am

Does this applies to True and False?

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]