Ren'Py How to save player clothes sets

Apr 24, 2020
192
257
Firstly... $ is "do single python command". It's just a shorthand alternative.
Yes, I'm aware that $ and default does different things. It just seemed like "copy this line of code, but use this instead of that" was a quick way of explaining things.

My point is they are independent of the code. So "put them in the init block" feels like mixing up two completely unrelated solutions ( the newer "default" solution and the older use of settings variables using "$" within init blocks).
I think you are mixing two observations I made, or it wasn't clear enough that they were meant to be separate.

My first observation was that the init block was unnecesary due to how default works.

My second observation was that LilyclothingSets shouldn't be reset every time Lily changed clothes. Instead that part of the code should have been moved up to the init block so that it was only called at the start of the game.
However, due to going through the code line by line, I had already pointed out that the default lines could stand on their own, which would also apply to LilyclothingSets.

You can see my intentions in the lines of code that I provided, since I only used an init block to make a function to change clothing sets.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,359
15,270
There used to be a practice of initializing variables as part of the init process using "$" - but there are some consequences for save files which is the reason why default was created as a unique command.
The problem isn't only linked to the save files.

An "init" block is only proceeded once, when Ren'py start. When the value of a variable created at "init time" is a scalar-like (string and numbers, probably also bool), it's not a problem. The value have changed, the variable is now savable, and it will be restored at its starting value if you restart the game.
But when the value isn't a scalar-like, so even if it's a list or a dictionary, it's something different that will happen :
Code:
init python:
    initVar = [ 0 ]

default defaultVar = [ 0 ]
define defineVar = [0]

label start:
    "'initVar' is [initVar]\n'defaultVar' is [defaultVar]\n'definetVar' is [defineVar]"
    $ initVar[0] += 1
    $ defaultVar[0] += 1
    $ defineVar[0] += 1
    "The value have been incremented"
    "'initVar' is [initVar]\n'defaultVar' is [defaultVar]\n'definetVar' is [defineVar]"
    "Now return to the main menu, and play this again for a surprise."
    "END"
    return
As you can see, only the variable created by default have been recreated by Ren'py. The two other will start with the last value they had when you decided to go to the main menu and restart the game.

Of course, this is a minor problem, both initVar and defineVar will not be saved. But you can use them to store information that are only relative to this particular play ; I don't know, by example (totally ridiculous) the number of time you visited a given location during this play.
It doesn't matter that the value is reset when you load a save file, but then you expect it to also be reset if you start a new game, what will not be the case.

Obviously, as I said it's a minor problem ; a value that isn't saved shouldn't be changed. But it sometimes happen, for cases less ridiculous than my example above. Therefore, it's to know.