Code: Select all
#rp for K
default rp_k = 0
#rp for P
default rp_p = 0
#rp for S
default rp_s = 0
#rp for Y
default rp_y = 0
python:
def inc():
nonlocal [rp_y]
rp_y += 1
def dec():
nonlocal [rp_y]
rp_y -= 1
label start:
menu:
"This should lower rp for Y":
$ dec()
"This should increase your rp for Y":
$ inc()
"Y's RP for you is now [rp_y]"
$ rp_y = 1+rp_y
I'm a pretty big beginner in Python but I want to try to learn how to make this quick and efficient since I want many menu choices to either increase or decrease rp_y without having to write a long string.
https://i.imgur.com/403UNgC.png
here I went on Jupyter to test out what i wanted to do (I used the global variable instead of nonlocal but both weren't working in renpy) and it worked fine so i'm not really sure what i'm really doing wrong.
error message:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 35, in script
File "game/script.rpy", line 35, in <module>
NameError: name 'inc' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 35, in script
File "C:\Users\xxx\Documents\renpy-7.0.0-sdk\renpy\ast.py", line 862, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\xxx\Documents\renpy-7.0.0-sdk\renpy\python.py", line 1912, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 35, in <module>
NameError: name 'inc' is not defined
Windows-8-6.2.9200
Ren'Py 7.0.0.196
Testing Area 1.0
Sat Jun 30 10:43:44 2018