Exact behaviour of after_load?

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.
Post Reply
Message
Author
FlashFrontal
Newbie
Posts: 10
Joined: Wed Jan 05, 2022 6:14 pm
Contact:

Exact behaviour of after_load?

#1 Post by FlashFrontal »

So, lets say I've got a first version of a game, with a bunch of variables that get defined in a label called variableSet which is called right at the beginning of the start label.

Later on, I release an update for the game that includes nw content, and subsiquently, nw variables. But players save files are already at the end of the first version of the game, so if I just add those new variables to the variableSet label, it won't be called again because the players save file is already beyond the start of the start label. (Of course I could have it call variableSet again, but then that would reset the values of all the variables defined in the first version.)

My original plan was to just have a label that gets called at the start of the new update which will define just the new variables. However, one of the new variables is used by a screen which is available in the first version. This would mean that any save files made in the first version of the game won't have that variable defined, and so using that screen before the player reaches the start of the new update will break the game.

I've heard about the after_load function which is called whenever a player loads a game. If I were to use it to define my new variables in there (Lets say they're all set to False), then I understand that this would mean that the variables are now defined regardless of at what point in the game the save is from. However, if the player was to play on to the point where one of these new variables is changed from its original value, and then saves the game, would loading that save trigger after_load again, and reset that variable back to its originally defined value?

Essentially I guess I'm just wondering whether after_load will update existing variables, or just add new ones? (In this context)

I know there must be a good solution to this, I just want to avoid forcing people to create new saves every time a new update is released. I'll do some testing at some point, but I just wonder if there's a better solution that I haven't touched upon here?

Many thanks :D

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Exact behaviour of after_load?

#2 Post by Ocelot »

Game does call after_load every time you load a game. THe behavior does not differs from if you called it manually.

In any medium-to-large early access project caring about save compatibility after_load label is a mess, taking into account version save is originally made, current progress and other things to make sure that game state is correct for current version of the game.
< < insert Rick Cook quote here > >

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Exact behaviour of after_load?

#3 Post by PyTom »

If all you want to do is to give new variables a default value, the default statement is the way to go - it will set the variable to a value if it hasn't been set before.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

FlashFrontal
Newbie
Posts: 10
Joined: Wed Jan 05, 2022 6:14 pm
Contact:

Re: Exact behaviour of after_load?

#4 Post by FlashFrontal »

PyTom wrote: Tue May 24, 2022 9:54 am If all you want to do is to give new variables a default value, the default statement is the way to go - it will set the variable to a value if it hasn't been set before.
Thanks, that's that works well. As long as they have a value of some sort when the game launches then I can continue without fear of it crashing out when they get called, and I can just have a label assign the correct value to each variable shortly before it becomes relevant.

I guess the youtube tutorial I watched 5 months ago skipped default and went straight to atl or something.

Post Reply

Who is online

Users browsing this forum: Andredron