My variable is not saving [solved]

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
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

My variable is not saving [solved]

#1 Post by nature1996 »

For my game I want to use a variable as a library. So I created tw variable:

Code: Select all

$fact=[None, None, None, None]

$ifact=["item 1","item 2","item 3","item 4"]
The afterward, I update the list as object are unlocked:

Code: Select all

$fact [1]=ifact [1]
That work just well. The problem is that as soon as I save and quit, or I reload the game, these two reset to their original value. No other variable do that, and I dont know what to do.
Last edited by nature1996 on Fri Jun 30, 2017 9:05 pm, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: My variable is not saving

#2 Post by trooper6 »

Best practices is to declare your variables using default outside of any label. For example:

Code: Select all

default fact=[None, None, None, None]
default ifact=["item 1","item 2","item 3","item 4"]

label start:
    "Whatever you have going on."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: My variable is not saving

#3 Post by nature1996 »

I tryed that. Also, i called them in a init section befor the start label

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: My variable is not saving

#4 Post by Ocelot »

Also, i called them in a init section befor the start label
This is probably the case. Code in init section is executed every time game is started or loaded. So, if there is something setting variables to some value, these variables would be set to that value, overwriting any saved data.

Do not assign anything in init section unless you intend to never change those variables
< < insert Rick Cook quote here > >

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: My variable is not saving

#5 Post by nature1996 »

As I sqid before, I tried it three way (default define and init) and all the time my value dissapear. Also, I have a lot of other variable wich value are saved wich are called in the init section.

I believe the problem might be because its an array, but I don't know....

I will try to put a part of my code later on.

Edit: I tryed it again as default, and I deleted the save file and recompiled everything, and now it works.
Je parle aussi français

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: My variable is not saving

#6 Post by trooper6 »

nature1996 wrote: Edit: I tryed it again as default, and I deleted the save file and recompiled everything, and now it works.
Default is the way to go (except for persistent variables which use define). There was a more complicated way of doing it all before default was introduced, but now we have default, and that is the way to go.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users