[SOLVED] Confusion over permanent variables

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
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] Confusion over permanent variables

#1 Post by Kinmoku »

Hi guys,

I'm not a very good coder and I'm trying to understand more about permanent game data, such as variables which will stay there even when you restart the game and play again.

At the start, I have the following code:

Code: Select all

label start:
    default arrives = False
    $ found = []
So each time the game starts up, the majority of variables reset and the game starts a new. However, I want to create some variables which stay permanent no matter how many times you play and I've never done that before...

I want to create another list called $ endings_unlocked = [] but I'm unsure where to put it. I'd the endings unlocked to stay permanently and only be removed if you delete/ uninstall the game. How do I do this?
Last edited by Kinmoku on Fri Jul 29, 2016 12:24 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: Confusion over permanent variables

#2 Post by trooper6 »

Kinmoku wrote:Hi guys,

I'm not a very good coder and I'm trying to understand more about permanent game data, such as variables which will stay there even when you restart the game and play again.

At the start, I have the following code:

Code: Select all

label start:
    default arrives = False
    $ found = []
So each time the game starts up, the majority of variables reset and the game starts a new. However, I want to create some variables which stay permanent no matter how many times you play and I've never done that before...

I want to create another list called $ endings_unlocked = [] but I'm unsure where to put it. I'd the endings unlocked to stay permanently and only be removed if you delete/ uninstall the game. How do I do this?
So first off, let's look at the code you provided.

Before your game starts (in other words, before the start label, not in the start label) is when you declare your variables. So you should have this instead:

Code: Select all

default arrives = False
default found = []

label start:
    "Blah blah blah"
Next, if you want to have a variable that lasts between games, you want persistent variables.
Here is the documentation of persistent variables: https://www.renpy.org/doc/html/persistent.html
However, here is the newer update on how to define persistent variables: https://www.renpy.org/doc/html/changelo ... provements

This would look like this:

Code: Select all

default arrives = False
default found = []

define persistent.endings_unlocked = [ ]

label start:
    "Blah blah blah"
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
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: Confusion over permanent variables

#3 Post by chocoberrie »

What you're looking for is persistent data. :)

Here are some links to threads for implementing persistent data in different ways for VNs:

Chapter Menus: One | Two
Unlockable episodes | paths/routes
Unlockable bonus scenes
Adding main menu options after 1st playthrough
Unlockable gallery
In-game achievements

I hope this helps!

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Confusion over permanent variables

#4 Post by Kinmoku »

trooper6 wrote:Before your game starts (in other words, before the start label, not in the start label) is when you declare your variables. So you should have this instead:

Code: Select all

default arrives = False
default found = []

label start:
    "Blah blah blah"
Next, if you want to have a variable that lasts between games, you want persistent variables.
Here is the documentation of persistent variables: https://www.renpy.org/doc/html/persistent.html
However, here is the newer update on how to define persistent variables: https://www.renpy.org/doc/html/changelo ... provements

This would look like this:

Code: Select all

default arrives = False
default found = []

define persistent.endings_unlocked = [ ]

label start:
    "Blah blah blah"
Oh thank you, this is a great help! I've always put the variables under start for some reason :P Thanks for the advice!
chocoberrie wrote:What you're looking for is persistent data. :)

Here are some links to threads for implementing persistent data in different ways for VNs:

Chapter Menus: One | Two
Unlockable episodes | paths/routes
Unlockable bonus scenes
Adding main menu options after 1st playthrough
Unlockable gallery
In-game achievements

I hope this helps!
Ahhh, so I'd been searching for "permanent" and nothing showed up XD These links all look super useful though, so thank you for sharing! :)

Post Reply

Who is online

Users browsing this forum: No registered users