"$ sin_points += 1" not working

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
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

"$ sin_points += 1" not working

#1 Post by Rinzamakani »

Hello. Lately, I've tried to add a sin or kill meter to my game. But when I defined it, I got this error:

Code: Select all

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/killshadow.rpy", line 4, in script
    $ sin_points += 1
  File "game/killshadow.rpy", line 4, in <module>
    $ sin_points += 1
NameError: name 'sin_points' is not defined

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

Full traceback:
  File "game/killshadow.rpy", line 4, in script
    $ sin_points += 1
  File "D:\renpy-6.99.12.4-sdk\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\renpy-6.99.12.4-sdk\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/killshadow.rpy", line 4, in <module>
    $ sin_points += 1
NameError: name 'sin_points' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
Love's Apathy 1.0
However, a person who checked my script said that everything was fine.
here's the code I used in my files:

In Script.rpy...

Code: Select all

default sin_points = 0
**This is above the label start**

And in the part where it's supposed to change the value within the story, after the label start:

Code: Select all

label killshadow:
   stop music fadeout 1.0
   play music "underwater.mp3"
   $ sin_points += 1
This works for a character of mine but I'm not sure why it isn't working for this. I even tried to define "sin" as a character but no luck.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: "$ sin_points += 1" not working

#2 Post by Remix »

It appears that you are doing things correctly...
As such I can only guess that perhaps persistent data (especially if running from a previous save) might be the cause. Does it still glitch if you delete persistent and start from the start?
Frameworks & Scriptlets:

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: "$ sin_points += 1" not working

#3 Post by Rinzamakani »

Remix wrote: Thu Oct 05, 2017 4:09 pm It appears that you are doing things correctly...
As such I can only guess that perhaps persistent data (especially if running from a previous save) might be the cause. Does it still glitch if you delete persistent and start from the start?
That seemed to be the problem. Since I was playing the game from a previous save file that didn't have the code. Thanks. :)

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: "$ sin_points += 1" not working

#4 Post by trekopedia »

The problem has to be with something you aren't showing in your code examples. A good way to deal with an issue is to try to isolate the problem entirely to determine if your core code is working. Then you can steadily eliminate possibilities. Try creating a new project with the entire script as follows:

Code: Select all

default sin_points = 0

label start:

    $ sin_points += 1
    "Sin Points = [sin_points]"
    jump start


    return
If you put this in a new project of your own and run it, you can verify that your sin_points are incrementing correctly. Thus, you know that the problem isn't in the syntax for the sin_points itself.

Without seeing more of your code, it is unclear why you are getting your error. However, the "+=" is triggering an error because python is looking for an existing variable of that name to which to add 1. That variable must already exist and be 'visible' to python at this location in the script. That means your original declaration is *not* visible for some reason...

If you post more code, perhaps someone will spot why your original declaration is not working.

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: "$ sin_points += 1" not working

#5 Post by trekopedia »

LOL. I posted right after you... disregard!

Post Reply

Who is online

Users browsing this forum: No registered users