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.
default result = 42 # default value of the global var
init python:
def my_add(x): #unique name
global result # use global var "result" not a local one for this function
result += x
#print (result) # this will print the result in console
screen add_scr():
key "a" action Function(my_add, 3)
key "s" action Function(my_add, -3)
text "[result]" align(0.5,0.05) # a way to show value
# The game starts here.
label start:
"..."
show screen add_scr # screen must be shown to let player operate the result var
"... ..."
"?!"
That was my mistake - name of custom function in a Function action doesn't need quotes.
In Ren'Py there are number of ways to show text (print will show it in console, also text might be shown in a screen, or "said" by character).
Variables used in a function are local for this function if not specified to use some global ones. In this sample screen will affect a global var "result". https://www.renpy.org/doc/html/python.html