I lose my items in the Inventory after loading the game

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
lolosa
Newbie
Posts: 19
Joined: Sat Feb 22, 2014 3:11 pm
Contact:

I lose my items in the Inventory after loading the game

#1 Post by lolosa »

Hi
I am working on the Inventory code that was in cookbook
http://www.renpy.org/wiki/renpy/doc/coo ... ney_System
i used it in a different way cause i let the user put things in his inventory(cause the game has nothing to do with money and stores)
so user adds thing any time at the Inventory .when the game saved and be loaded again before closing the game everything is good..but when i close the game and open it then load the game i always find the Inventory is empty
..
that's because i put this line in the initial part
inventory = myInventory()
so every thing we'll be start again as its first time

but this impotent to keep the Inventory stores other items they will be added during the game (if i put this line in the start label
it will save only the items i add them when the game starts even with loading before exit the game .

i think to solve this i need to stop the initial code (init python) when the game not new ( loaded )
or
i need the store my Inventory in external file so the code will get the variable from the file

or
saving my Inventory inside the load method

unfortunately i dont know how to do any of these,i tried but i coudnt
so anyone can help

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: I lose my items in the Inventory after loading the game

#2 Post by Alex »

Try to move <inventory = myInventory()> from init to start label, like

Code: Select all

#init:
    #$ inventory = myInventory()

label start:
    $ inventory = myInventory()
    "..."

lolosa
Newbie
Posts: 19
Joined: Sat Feb 22, 2014 3:11 pm
Contact:

Re: I lose my items in the Inventory after loading the game

#3 Post by lolosa »

if I put this line in the Start label it will not save the items those are added by the user during the game
i need a way to save the Inventory in safe place like in external file

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: I lose my items in the Inventory after loading the game

#4 Post by Asceai »

lolosa wrote:if I put this line in the Start label it will not save the items those are added by the user during the game
Why won't it? It just stores those things in a list. Doesn't matter if they are newly-created items or not.

Give us an example of something that will break if you declare the inventory after label start.

lolosa
Newbie
Posts: 19
Joined: Sat Feb 22, 2014 3:11 pm
Contact:

Re: I lose my items in the Inventory after loading the game

#5 Post by lolosa »

i found this ..i think it is the situation here
http://www.renpy.org/wiki/renpy/doc/coo ... nit_blocks

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: I lose my items in the Inventory after loading the game

#6 Post by Showsni »

If the inventory is in an init block, it will lose everything when you reload. If it's after the start label, though, it will save properly. Just make sure anything (variable, list, etc.) you want saved isn't in an init block, and is instead somewhere in the script after the start label.

Post Reply

Who is online

Users browsing this forum: No registered users