If in screens.repy I put this code:
[...]
It is necessary to include in gui.rpy:
Or is it not necessary?
Thanks for your help.
TL;DR ... Use
default persistent.ailein.fotos = 0
. Don't use
define
and don't use the
init -1 python:
code.
The longer version... Let's talk through each of these options...
Python:
init -1 python:
if persistent.ailein_fotos is None:
persistent.ailein_fotos = 0
During RenPy startup (
init -1 python
), the game will check if a persistent variable
ailein_fotos
currently has no type. That is, it's not a string, boolean, integer, float or any other type of variable. In effect, it's checking if the variable exists (which only possible this way, because it's
persistent.
and persistent variables return
None
if they don't exist).
If the game decides the persistent variable doesn't already exist, it sets the value to 0 (zero).
While the code will run ever time the game starts, the
is None:
will only be True the very first time, since it immediately changed to zero (an integer type).
I personally wouldn't put that code in either
screens.rpy
or
gui.rpy
, but since RenPy doesn't actually care what the files are called and treats all files (more or less) equally, I suppose it makes as much sense as anywhere else. Especially since it relates to the screen code for your foto gallery. (If I were to use this code, I would put it at the top of
script.rpy
. But only because that is the first script anyone ever looks at and most "first time" code happens there).
Python:
define persistent.ailein.fotos = 0
This would create a new variable/object called
persistent.ailein.fotos
. Or at least it normally would, however...
define
statements not specifically included within another
init:
level will run at
init 0:
. Since python/RenPy process the init blocks in numerically order (from low to high... think -999 to +999), that means the -1 block (
if persistent.[...]
) will run before the 0 block (
define [...]
).
Because the variable already exists by the time the
define
is processed... it doesn't actually do anything.
Plus, as
I've mentioned before in the other thread,
define
is supposed to only be used for variables/objects that will never change while the game is running. They are supposed to be fixed, unchanging values. (Not the case here).
For both these reasons, I don't think
define
should be used here.
Python:
default.persistent.ailein.fotos = 0
First things first, I think there's a typo in there. There shouldn't be a fullstop between
default
and
persistent.ailein.fotos
.
default
too would create the variable. And like my explanation of the
define
code, would do nothing because the variable would already have been created during the init stages of the game startup.
default
works in much the same way as your
init -1 python:
code. It will create a variable of that name, if one doesn't already exist.
Since it does exactly the same thing, you don't need both.
Personally, I would use the
default persistent.ailein.fotos = 0
and not the
init -1 python:
code. Not least because it's considerably less complicated and quicker to type. And again, I would put it near the top of the
script.rpy
file.