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.
What's the correct way to declare and use local variables in a screen? Every time I've tried to use local variable, they somehow store data that messes up my code. I know it's my fault, so I need to figure this out once and for all.
screen test():
# which way is the correct way to declare a local variable in a screen?
# THIS?
default shortenString = "dir1/dir2/" + someVar + anotherVar + "this_that" + tableXYZ[x].data
# OR THIS?
$ shortenString = "dir1/dir2/" + someVar + anotherVar + "this_that" + tableXYZ[x].data
imagebutton:
idle shortenString + "_idle.png"
hover shortenString + "_hover.png"
Last edited by henvu50 on Thu Jul 15, 2021 10:21 pm, edited 1 time in total.
The former is actually a screen variable, the latter is a local variable, that's where the SetScreenVariable and SetLocalVariable actions come into place.
If you want a static-like declaration of something when the screen is called/shown and have it update only at specific interactions, then use screen variables.
If you want a variable to update every interaction then use local variables.
Basically, local variables are unstable since they get updated every interaction, while screen variables only update through SetScreenVariable action.
A good example that exactly shows the difference...