[Solved] List not saving until after next line of text

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
User avatar
Kinjo
Veteran
Posts: 219
Joined: Mon Sep 19, 2011 6:48 pm
Completed: When the Seacats Cry
Projects: Detective Butler
Organization: Goldbar Games
Tumblr: kinjo-goldbar
Deviantart: Kinjo-Goldbar
Github: GoldbarGames
Skype: Kinjo Goldbar
itch: goldbargames
Location: /seacats/
Contact:

[Solved] List not saving until after next line of text

#1 Post by Kinjo »

This one is hard to explain, and hard to think of a solution, so here I am.

I've got an inventory system that makes use of a list of Items (a class). The button to access this inventory is available on every screen. From within the inventory screen, one can click on the Craft button to select certain items and -- you guessed it -- craft them into a more powerful item. Doing so removes those items from the list and adds the new item.

Now here's the problem. Suppose my inventory list is [A, B, C] and I combine A, B, and C to make D. Then my list becomes [D]. That's fine so far.

However, let's also say I save the game right after doing this. So Save1 should, when loaded, contain [D] in the inventory list.

I decide to advance the text by one, by closing out the inventory screen and clicking the mouse as usual to advance text. Now I save into Save2. The list here should also be [D].

Now I close out of the game, start it up, and decide to load Save1. Instead of seeing [D], I open the inventory to find [A, B, C] as though I never crafted them.

However, if I load Save2, I see [D] just as I expected. So it appears that my changes only remain intact if I save on a line after the one where I crafted something.

Why exactly is this the case, and how can I get around this?
Last edited by Kinjo on Sat Feb 20, 2016 3:54 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: List not saving when updated until after next line of te

#2 Post by PyTom »

That's correct, Ren'Py saves at the start of a statement. You can try using renpy.retain_after_load to work around this, but it's semantically weird, so if it causes any problems they're on you.
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

User avatar
Kinjo
Veteran
Posts: 219
Joined: Mon Sep 19, 2011 6:48 pm
Completed: When the Seacats Cry
Projects: Detective Butler
Organization: Goldbar Games
Tumblr: kinjo-goldbar
Deviantart: Kinjo-Goldbar
Github: GoldbarGames
Skype: Kinjo Goldbar
itch: goldbargames
Location: /seacats/
Contact:

Re: List not saving when updated until after next line of te

#3 Post by Kinjo »

Thank you, that worked perfectly!

Post Reply

Who is online

Users browsing this forum: Google [Bot]