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.
-
Kaen
- Regular
- Posts: 148
- Joined: Tue Oct 16, 2012 10:49 pm
-
Contact:
#1
Post
by Kaen » Tue Sep 23, 2014 6:30 pm
I'm trying to make a python function that changes the value of a variable:
Code: Select all
# The game starts here.
label start:
python:
num = 1
def add_num():
num += 1
return num
label testing:
$ newnum = add_num()
"[newnum]"
But I'm receiving an error:
Code: Select all
UnboundLocalError: local variable 'num' referenced before assignment
What should I do so I don't need to write
$ num += 1 everytime I want this to happen through my game? I wish I could use a function to do this to me...
Last edited by
Kaen on Wed Sep 24, 2014 11:04 am, edited 1 time in total.
-
Kaen
- Regular
- Posts: 148
- Joined: Tue Oct 16, 2012 10:49 pm
-
Contact:
#3
Post
by Kaen » Wed Sep 24, 2014 11:04 am
Thank you very much Alex, it worked!
Users browsing this forum: Bing [Bot]