Page 1 of 1

default declared variable not being saved after being changed.

Posted: Mon Nov 05, 2018 11:47 pm
by henvu50
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)


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

Posted: Tue Nov 06, 2018 12:04 am
by henvu50
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?

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

Posted: Tue Nov 06, 2018 12:19 am
by henvu50
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

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

Posted: Tue Nov 06, 2018 12:34 am
by Imperf3kt
I think renpy.restart_interaction is what people generally use
https://www.renpy.org/doc/html/other.ht ... nteraction

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

Posted: Tue Nov 06, 2018 1:47 am
by henvu50
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?

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

Posted: Tue Nov 06, 2018 4:32 am
by Imperf3kt
I assume so. Just do one action, but put a comma between the actions themselves.