Ren'Py variables and saving.

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
[Elysium] Véronique
Newbie
Posts: 8
Joined: Wed Feb 07, 2018 4:54 pm
Projects: My First Castellan
Organization: Elysium Studios
Deviantart: elysiumcoop
Github: kawaiidesune
itch: elysiumgames
Location: Longmont, CO
Contact:

Ren'Py variables and saving.

#1 Post by [Elysium] Véronique » Mon Apr 23, 2018 7:13 pm

Okay, so I was reading through this article and I must confess to being a bit confused. I'm confused because I wonder, if I define a variable (like an integer) and make changes to it using the standard Python language, DOES the current state of the variable at the time of saving get saved when the game is saved? And when it is loaded up, does the variable get overwritten by the initial instantiation of these variables or not? Like, let's say I assign a variable named "e" at the beginning of the script a value of 50 and at the time of save, it is 74. When that save file is loaded, is it reset to 50 or is the previous value of 74 saved?

Do I have to do something special to make this happen or not? I apologize for asking what may seem like a basic question but I'm legitimately confused.
Véronique Bellamy, DPhil
Founder, Elysium Studios

kivik
Miko-Class Veteran
Posts: 784
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Ren'Py variables and saving.

#2 Post by kivik » Mon Apr 23, 2018 7:42 pm

It's a shame the documentation examples are a bit sparse at the moment and leaves to confusions.

If you read this part of the documentation about define and default as well, it'll make more sense:

https://www.renpy.org/doc/html/python.h ... -statement

Long story short, you want to use default to make sure variables are saved. For ints and strings, defined variables will be saved so long as they're changed within the game flow, the problem is defined objects being referenced can be gone forever.

User avatar
[Elysium] Véronique
Newbie
Posts: 8
Joined: Wed Feb 07, 2018 4:54 pm
Projects: My First Castellan
Organization: Elysium Studios
Deviantart: elysiumcoop
Github: kawaiidesune
itch: elysiumgames
Location: Longmont, CO
Contact:

Re: Ren'Py variables and saving.

#3 Post by [Elysium] Véronique » Mon Apr 23, 2018 8:19 pm

"can be gone forever"

... how, pray tell? I ask because I'd like to try to control for it. :)
Véronique Bellamy, DPhil
Founder, Elysium Studios

User avatar
[Elysium] Véronique
Newbie
Posts: 8
Joined: Wed Feb 07, 2018 4:54 pm
Projects: My First Castellan
Organization: Elysium Studios
Deviantart: elysiumcoop
Github: kawaiidesune
itch: elysiumgames
Location: Longmont, CO
Contact:

Re: Ren'Py variables and saving.

#4 Post by [Elysium] Véronique » Mon Apr 23, 2018 8:22 pm

Also, if I write something like this:

Code: Select all

define sample = 1

label start:
     sample = 5
     # insert game logic here.

Will sample be equal to 1 or 5 once I load the save file if I put all the logic of the novel AFTER assigning that variable to 5?
Véronique Bellamy, DPhil
Founder, Elysium Studios

kivik
Miko-Class Veteran
Posts: 784
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Ren'Py variables and saving.

#5 Post by kivik » Mon Apr 23, 2018 8:46 pm

Ok just to be on the safe side - I'm going to recommend you do this for any variables that are subjected to change:

Code: Select all

default sample = 1
And this if the variable will never every change under any circumstances:

Code: Select all

define fixed_value = 1

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

Re: Ren'Py variables and saving.

#6 Post by trooper6 » Mon Apr 23, 2018 10:44 pm

If you use default outside of any label to initialize your variables that will change, then it will save those variables. Using default means it will not overwrite the variable.

Default means: If there is no other value for this variable, use the default.
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