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.
I created an event system to use for my game, the system is fairly straight forward. As the player makes choices available events are added to a python list:
init python:
events = []
label start:
me "I talked to a girl, that means I get to add an event."
$ events.append("girlTalk")
...
if "girlTalk" in events:
jump girlTalk
label girlTalk:
me "This is the event that corresponds to the added event."
$ events.remove("girlTalk") # Event has been completed, no longer needed.
Let me be clear: playing through normally has no issues. However, if I save the game before I hit the conditional that plays the event and I load from that save, the event will not trigger.
Is this expected behavior? Is it possible to fix this?
Essentially any code inside an init block is run before the game starts, so you're reseting the events to a blank list every time you load a save game.
kivik wrote: ↑Sat Apr 28, 2018 5:24 am
Essentially any code inside an init block is run before the game starts, so you're reseting the events to a blank list every time you load a save game.
This is slightly incorrect. Loading variable values from saved game happens after init phase.
The actual problem is that events is not saved in the first place: RenPy adds to list of saved variables only references which were changed after game start. events never chnges after setting it in int block, so it is not saved at all. Object it refers to is mutated, but RenPy does not care about that.
Essentially variable is saved only if it is assigned something directly after game start: events = . . ..
kivik wrote: ↑Sat Apr 28, 2018 5:24 am
Essentially any code inside an init block is run before the game starts, so you're reseting the events to a blank list every time you load a save game.
This is slightly incorrect. Loading variable values from saved game happens after init phase.
The actual problem is that events is not saved in the first place: RenPy adds to list of saved variables only references which were changed after game start. events never chnges after setting it in int block, so it is not saved at all. Object it refers to is mutated, but RenPy does not care about that.
Essentially variable is saved only if it is assigned something directly after game start: events = . . ..
Ah I realised where my logic fell apart! I thought since he did events.append() in his start label that the variable did get modified and therefore should be saved - but the fact that it wasn't made me think it must have been overwritten by the init process.
But thinking about it - I remember documentation saying something about differences with pointers and values, and since events is a list, it's a pointer which wasn't set after init and thus wasn't saved. Evidently still confuses me at times, that's why I always say declare everything in default to be safe for saving