default declared variable not being saved after being changed.

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: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

default declared variable not being saved after being changed.

#1 Post by henvu50 » Mon Nov 05, 2018 11:47 pm

I set the variable to 99 when the mouse hovers over the textbutton.

I check console using Shift O to ensure the variable changed from 52 to 99.

I save my game and reload.

The value goes back to the default of 52? Why won't the new value of 99 get saved?

Code: Select all


default test_var = 52

screen test_screen:

$print (test_var)

  vbox:
     textbutton "test":
     action Return(1)
     hovered (SetVariable("test_var", 99))

$print (test_var)


henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: default declared variable not being saved after being changed.

#2 Post by henvu50 » Tue Nov 06, 2018 12:04 am

Weird, I actually had to progress the game forward a little, then perform a save, now the stat gets saved.

So if a player changes a stat in a screen, they have to skip a line of dialogue before the stats will get saved? That doesn't make sense.

Let's say you have a character stat window. You change strength from 50 to 60. Now if you want that change to save, you have to skip through one line of dialogue?

henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: default declared variable not being saved after being changed.

#3 Post by henvu50 » Tue Nov 06, 2018 12:19 am

Okay, I had to add this one line of code and now it works:

Code: Select all


default test_var = 52

screen test_screen:

# add this to make sure changes are saved on a character skills menu for example
$ renpy.retain_after_load()    

$print (test_var)

  vbox:
     textbutton "test":
     action Return(1)
     hovered (SetVariable("test_var", 99))

$print (test_var)

$ renpy.retain_after_load() ensures that the changes get saved on that screen when doing a save.

This link someone gave me earlier helped a lot: https://www.renpy.org/doc/html/save_loa ... after-load

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: default declared variable not being saved after being changed.

#4 Post by Imperf3kt » Tue Nov 06, 2018 12:34 am

I think renpy.restart_interaction is what people generally use
https://www.renpy.org/doc/html/other.ht ... nteraction
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: default declared variable not being saved after being changed.

#5 Post by henvu50 » Tue Nov 06, 2018 1:47 am

Imperf3kt wrote:
Tue Nov 06, 2018 12:34 am
I think renpy.restart_interaction is what people generally use
https://www.renpy.org/doc/html/other.ht ... nteraction
So I should invoke two actions? One for SetVariable and another for renpy.restart_interaction?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: default declared variable not being saved after being changed.

#6 Post by Imperf3kt » Tue Nov 06, 2018 4:32 am

I assume so. Just do one action, but put a comma between the actions themselves.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

Users browsing this forum: Kia, span4ev