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.
after loading the game x was "some value" so it didn't change. At first I've thought it was supposed to work like this, but later I've read docs about define & default, according to docs it should be changed.
I can't find code or documentation that says for sure, but I think the problem is that init-time code (like define statements) is executed before the save is loaded. Then the value of the variable read in from the save file overwrites the init (defined) value, just like what would happen if you had
`Defines` sound like they should be constants but they're not; they are recorded in the store just like any other variable and can be changed later. The principal (only?) difference is that their values are assigned at init time and are not recorded in save files unless they're changed.
Last edited by zmook on Mon Mar 01, 2021 5:25 pm, edited 1 time in total.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
# v2
default a = 'hi'
label after_load:
$ a = 'hi' # to fix old saved values
It's kind of ugly and error-prone having to set the value in two places, though. Alternately, you could give up on the `default` statement altogether and do:
# v2a
label set_defaults:
if not hasattr(store, 'a') or a = 'hello':
a = 'hi'
return
label start:
call set_defaults
label after_load:
call set_defaults
Or, possibly best, just throw away the variable you need to change and replace it with a new one.
This post does not exactly answer, but give an idea that saved variables overwrite the variables defined with define statements as zmook mentioned.
This problem should appear only when loading save file that stores the variable. Basically, it is a compatibility problem.
If you want to ensure that the value of the variable is correct for old save files you can explicitly check it in its value in the after_load label:
I've changed variable name to a new one, I had a list of enemies hard coded inside a label, to give modders ability to add new enemies without changing vanilla files I moved it outside of a label so they can append to it at init time. I've written about this because I thought it might be a bug, so I wanted to provide feedback.