Values of variables out of date on screens shown with action ShowMenu()

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
Woetoo
Regular
Posts: 28
Joined: Sat Feb 09, 2019 9:48 am
Contact:

Values of variables out of date on screens shown with action ShowMenu()

#1 Post by Woetoo »

I wonder if anyone can explain what might be going on here.
I'm using RenPy 7.3.5

I'm trying to diagnose a stats screen which has been added to the main game menu. Though I've recreated the same problem by adding variables fields to the "About" screen too.

Essentially, I have this code.

Code: Select all

# Part of screens.rpy...

screen navigation():
        # [snip]
        if not main_menu:
            textbutton _("Stats") action ShowMenu("stats")
        # [snip]
 

Code: Select all

default my_var_1 = 0
default my_var_2 = 2
default my_var_3 = 0

screen stats():

    tag menu

    use game_menu(_("Stats"), scroll="viewport"):

        vbox:
            label "Value 1: [my_var_1]"
            label "Value 2: [my_var_2]"
            label "Value 3: [my_var_3]"
        
label start:

    "*** START ****"
    "Check the stats page now."
    
    $ my_var_1 += 1
    $ my_var_2 += 4
    $ my_var_3 += 3
    
    "Okay. Now check the stats page again."
    "*** THE END ***"
    return

What happens is that the stats screen seems to show cached values of the variables rather than their latest current values. Sometimes on the 2nd check of the values, the values can either be "0, 2, 0" or "1, 6, 3" depend on what has previously been shown. Flipping to another game menu screen (like About or Preferences) and then back to the Stats page refreshes the values and you see the actual current values.

I've tried referencing the values as store.my_var_1, etc - just in case it was a local/global thing with the same results.
I've tried using "text" fields instead of "label". Still no luck.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2398
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Values of variables out of date on screens shown with action ShowMenu()

#2 Post by Ocelot »

This is a problem with displayable caching. I was able to get around it by swithching to percent-substitution: label "Value 1: %s" % my_var_1
< < insert Rick Cook quote here > >

Woetoo
Regular
Posts: 28
Joined: Sat Feb 09, 2019 9:48 am
Contact:

Re: Values of variables out of date on screens shown with action ShowMenu()

#3 Post by Woetoo »

Cheers.

I did later find that "call screen" and "show screen" both have nopredict parameters but ShowMenu does not.

That sent me down a bit of a rabbit hole and I even ended up trying renpy.stop_predict_screen("stats") and renpy.stop_predict_screen("game_menu"). But neither of them seems to work how I thought they should. Perhaps they are not checked by the ShowMenu() process either (or I'm misunderstanding their usage).

If pytom ever reads this thread... then perhaps ShowMenu() needs a nopredict parameter too? Just for consistency sake?
Or perhaps the screen prediction mismatching of variables could be considered an actual bug?

Either way, I have a solution so I guess I'll just need to be consistently inconsistent about my string substitution solutions. Thanks @Ocelot.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2398
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Values of variables out of date on screens shown with action ShowMenu()

#4 Post by Ocelot »

nopredict would not help, because it is there to stop unnessesary reevaluations, and you have opposite problem: displayables are not getting reevaluated even when you need them to.

Other solutions could be:
1) Drop () from screen declaration: screen stats:. Due to how screens without argument list works, you cannot cache anything, because anything could change.
2) Add a python line anywhere before labels. E.g. $ nocache = 0. I assume that parser considers that python code could change anything and drops cache from that point.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]