Point Problems (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
lovelieslemons
Newbie
Posts: 8
Joined: Sun Oct 24, 2010 5:31 pm
Contact:

Point Problems (Solved)

#1 Post by lovelieslemons » Mon Oct 25, 2010 7:49 pm

Yet another newb question:
In my game, you must win arguements in order to progress. The arguements are based on the point system, but I keep getting this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

NameError: name 'Lilly_Trust_points' is not defined

While running game code:
 - script at line 226 of C:\Users\me\Desktop\Love, Lies and Lemons/game/script.rpy
 - python at line 226 of C:\Users\me\Desktop\Love, Lies and Lemons/game/script.rpy.

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

  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\bootstrap.py", line 254, in bootstrap
  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\main.py", line 310, in main
  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\main.py", line 93, in run
  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\execution.py", line 259, in run
  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\ast.py", line 574, in execute
  File "C:\Users\me\Desktop\renpy-6.11.1\renpy\python.py", line 957, in py_exec_bytecode
  File "C:\Users\me\Desktop\Love, Lies and Lemons/game/script.rpy", line 226, in <module>
NameError: name 'Lilly_Trust_points' is not defined

While running game code:
 - script at line 226 of C:\Users\me\Desktop\Love, Lies and Lemons/game/script.rpy
 - python at line 226 of C:\Users\me\Desktop\Love, Lies and Lemons/game/script.rpy.

Ren'Py Version: Ren'Py 6.11.1b
The relevant blocks of code are:

Code: Select all

label start:
   $ run = False
   $ Lilly_Approval_points = 0
   $ Lilly_Trust_Points = 0
   $ mad_science_Points = 
And:

Code: Select all

      show text "You have entered an arguement. You're aim is to gain Lilly's approval by  saying the right things. "
   menu:
    "Aren't we friends?":
        $ Lilly_Trust_points += 1
        j "Come on. Aren't we friends"
        hide l norm
        show l sup
        l "I suppose."
    "Explain":
        $ Lilly_Trust_points += 2
        j "Can you imagine how I must feel, not knowing where my sister is?"
        hide l norm
        show l sup
        l "I guess your right."
    "Threaten Her":
       $ Lilly_Trust_points -= 3
       j "If you don't, I'll-."
       hide l norm
       show l wid
       l "Glare at me all day?."
       
if Lilly_Trust_points > 2:
         l "Well, I guess I can trust you"
         jump expo
if Lilly_Trust_Points < 1 :
         l "There is no way I'm telling you anything!"
         jump suspend
          
Sorry, I got the wrong sub-forum. My newb-ness got ahead of me. Anyways, would a move be possible?
Last edited by lovelieslemons on Thu Oct 28, 2010 7:11 pm, edited 1 time in total.

fortaat
Regular
Posts: 183
Joined: Tue May 18, 2010 1:16 pm
Contact:

Re: Point Problems

#2 Post by fortaat » Mon Oct 25, 2010 7:56 pm

On the init block it's Lilly_Trust_Points while in the code it's Lilly_Trust_points.

It's a good practice to capitalize all your variables (the things that make the point system) to avoid such errors.

User avatar
lovelieslemons
Newbie
Posts: 8
Joined: Sun Oct 24, 2010 5:31 pm
Contact:

Re: Point Problems

#3 Post by lovelieslemons » Mon Oct 25, 2010 8:34 pm

Thanks for helping out, but I'm still getting the error.

fortaat
Regular
Posts: 183
Joined: Tue May 18, 2010 1:16 pm
Contact:

Re: Point Problems

#4 Post by fortaat » Mon Oct 25, 2010 8:52 pm

Does the error pop when you're loading a game, or when you first run it?
If it's the first, start a new game and see what happens.

User avatar
killdream
Veteran
Posts: 325
Joined: Wed Nov 05, 2008 1:05 pm
Projects: EVūL (WIP), insilo (WIP), Cute Demon Crashers!
Deviantart: robotlolita
Github: robotlolita
Location: World's End (aka Brazil)
Contact:

Re: Point Problems

#5 Post by killdream » Tue Oct 26, 2010 7:55 am

fortaat wrote:On the init block it's Lilly_Trust_Points while in the code it's Lilly_Trust_points.

It's a good practice to capitalize all your variables (the things that make the point system) to avoid such errors.
Actually, in Python it's best practices to write your variables in lowercase, with words separated by underscores.
Thanks for helping out, but I'm still getting the error.
Ren'Py saves the variables with a save file, but since you're defining variables at the `label start`, they won't be redefined when you load from this save game (since `label start` won't be executed). You have to delete your save file and start over.

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Point Problems

#6 Post by Jake » Tue Oct 26, 2010 9:28 am

killdream wrote:
fortaat wrote: It's a good practice to capitalize all your variables (the things that make the point system) to avoid such errors.
Actually, in Python it's best practices to write your variables in lowercase, with words separated by underscores.
Honestly, the important thing is just that you come up with some kind of convention and stick with it. So long as you personally always write your variable names in lowercase with underscores, or capital letters, or camel case or whatever, you can easily type the same variable name twice without thinking and have them identical letter-for-letter, case-for-case, which is the whole point.

Sure, it helps a little when you're writing Python to use lowercase with underscores just because that's what most Python code is written in so you'll find it easier to use example code and other Python programmers can read your code more quickly. And it might help a little in some other language (I don't know, COBOL?) if you make all your variable names uppercase. But since most people aren't going to be showing others their Ren'Py script that much, having a convention is more important than it being the same convention most other people use for that language, IMO.
Server error: user 'Jake' not found

User avatar
sake-bento
Eileen-Class Veteran
Posts: 1909
Joined: Sat Jan 26, 2008 5:58 pm
Completed: http://sakevisual.com/games.html
Projects: Every Sunrise, Shinsei
Organization: sakevisual
Tumblr: sakevisual
Deviantart: sakevisual
itch: sakevisual
Contact:

Re: Point Problems

#7 Post by sake-bento » Tue Oct 26, 2010 4:53 pm

Edit: I'll leave this post up, but I suggest reading Jake's posts below this before you consider trying it. While I think it's a solution to your problem, I'm not a master programmer by any stretch and it may create new problems if you use this.

--

You're creating the variables under the start label when you should be initializing them under init. Try something like so:

Code: Select all

init:
   $ run = False
   $ Lilly_Approval_points = 0
   $ Lilly_Trust_Points = 0
   $ mad_science_Points = 0

label start:
    "What a great day to perform some mad science with my trustworthy partner, Lilly!"
    menu:
        # All your menu stuff here
Also keep in mind that capitalization matters, as others have already said. If you capitalize something when you create it, you have to keep that same capitalization when you do things to it later.

And thread moved to the Ren'py support forum as requested.

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Point Problems

#8 Post by Jake » Tue Oct 26, 2010 5:49 pm

sake-bento wrote:You're creating the variables under the start label when you should be initializing them under init.
Actually, I would advise doing exactly what they did - initializing them right after the start label, and not in init.

Init is for things which don't change during the game - image and Character definitions and stuff like that. Things which are going to change in-game should be defined in-game as well.

It's probably actually OK for simple variables[*], but as a general rule declaring stuff which changes in an init block is asking for trouble with loading and saving - even for end-users, outside of development - and it's a bad habit to get into. Declaring your vars after the 'start' label means you have to play from the beginning during development, but you don't have to worry about the player's experience.





[*] By "simple variables" I basically mean "numbers, True/False values and maybe strings of text". Lists and dictionaries are likely to not be saved if you declared them in init, object instances are definitely problematic, but even strings can sometimes not get saved despite being saved.
Server error: user 'Jake' not found

User avatar
sake-bento
Eileen-Class Veteran
Posts: 1909
Joined: Sat Jan 26, 2008 5:58 pm
Completed: http://sakevisual.com/games.html
Projects: Every Sunrise, Shinsei
Organization: sakevisual
Tumblr: sakevisual
Deviantart: sakevisual
itch: sakevisual
Contact:

Re: Point Problems

#9 Post by sake-bento » Tue Oct 26, 2010 6:41 pm

A quick look over some code I've nicked from a couple other Ren'py developers shows variables being declared under the init tag rather than after the start, and initialized within the game when necessary (in the case of complex variables like arrays).

lovelieslemons, are you getting this error, even if you start playing the game from the very beginning?

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Point Problems

#10 Post by Jake » Tue Oct 26, 2010 7:31 pm

sake-bento wrote:A quick look over some code I've nicked from a couple other Ren'py developers shows variables being declared under the init tag
Then those other Ren'Py developers had bad habits in this case.

Seriously, I would strongly recommend against declaring anything that changes in-game in an init block, whatever people have or haven't got away with in the past. It's guaranteed to break for some data types and iffy for some others. PyTom has given exactly the same advice in the past, for that matter.
Server error: user 'Jake' not found

User avatar
lovelieslemons
Newbie
Posts: 8
Joined: Sun Oct 24, 2010 5:31 pm
Contact:

Re: Point Problems

#11 Post by lovelieslemons » Thu Oct 28, 2010 7:11 pm

Thanks to every body who responded, I took all your advice and fixed the problem. I'm not getting the error when i start from the beggining, only when I load. Anyways, Thanks for your help.

Post Reply

Who is online

Users browsing this forum: Google [Bot]