I was able to change & save a $ declared variable. How is that possible?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

I was able to change & save a $ declared variable. How is that possible?

#1 Post by henvu50 »

I was told that I must use default when declaring flags for variables that can change during gameplay. It turns out that variables declared with $ can also be changed and saved. Was this a recent change to renpy?

This variable can be changed and then saved:

Code: Select all

label test:
   $ storyflag1 = False
I was able to set storyFlag1 to true using SetVariable, then I saved the game, when I reloaded that save, the storyflag1 value was still True.

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

Re: I was able to change & save a $ declared variable. How is that possible?

#2 Post by Alex »

Have you seen this - https://www.renpy.org/doc/html/python.html ?

Other words,

Code: Select all

default var = 1
is a bit more than just

Code: Select all

label start:
    $ var = 1
It does the same thing - sets the variable's value, but also adds the variable if it wasn't declared before (useful for patches and addons for the game).

So, you still can declare (sets the default value) your variables in label (at the very beginning of the start label - to prevent situation when you try to evaluate variable that wasn't declared (set, created) yet).

As you have read(https://www.renpy.org/doc/html/save_load_rollback.html), things that have changed in game are saveable, so it's ok if you change the variable using one line python code ($-sign), or use screen action, or python block. Take note, that "Saves occur at the start of a Ren'Py statement ", so you unable to properly save game state in the middle of python block. The same is about screens - you can interact with screen, change variables, but changes will be saved when the next Ren'Py statement will be executed (unless you've use renpy.retain_after_load).

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]