[SOLVED] Information in hud screens not autorefreshing

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
RVNSN
Regular
Posts: 36
Joined: Mon Apr 08, 2019 3:54 pm
Projects: Lust & Piracy
itch: rvnsn
Contact:

[SOLVED] Information in hud screens not autorefreshing

#1 Post by RVNSN »

In my hud, I have imagebuttons to show things like inventory (booty) and location, each opens another screen for their individual displays. The inventory (booty/treasure chest) presently just displays the amount of money. If there is a change in money, or a change in location, when you open either it displays the information it last displayed, not the current information, so you have to open that screen (displays old info), close screen, then open again (displays new information). And if you load a save, it first displays the information it displayed prior to loading the save.

I thought I knew what I needed to do to fix this, as a somewhat similar problem had come up with the time display a few updates ago, and some wonderful members here shared their wisdom to fix it, but after trying to apply the same idea, it did not work.

This might be a bit overkill, but I'm including the complete hud code here:

Code: Select all


screen hud():

    vbox:
        fixed:
            imagebutton xalign 1.0 ypos 5:
                idle "gui/ships_log_cover_idle.png"
                hover "gui/ships_log_cover_hover.png"
                action [Show("shipslog_hud"), Hide("hud")]# Show("statpage_hud") ##, Show("statshide_hud")

            $ money_string = format_money(money)

            imagebutton xalign 0.01 ypos 990:
                idle "gui/treasure_chest_closed_gui_idle.png"
                hover "gui/treasure_chest_closed_gui_hover.png"
                action [Show ("booty2_hud"), Hide("hud")]

            imagebutton auto "gui/map_closed_%s.png":
                xalign 0.99
                ypos 875
                action [Show("location2_hud"), Hide("hud")]

#            $ daycount = day

            $ day_number = (day%7)
            $ day_name_values = ("Wed", "Thur", "Fri", "Sat", "Sun", "Mon", "Tue")
            $ dayn = day_name_values[day_number]

            $ dtime_number = (dtime%5)
            $ dtime_name_values = ("Morn", "Midday", "Sunset", "Night", "Nocturn")
            $ dtimen = dtime_name_values[dtime_number]


            $ daynumber_str = __("{color=#C0C0C0}{size=-20}%s{/size}{/color}") % (day)

            $ daytime_str = __("{color=#C0C0C0}{size=-24}%s %s{/size}{/color}") % (dayn, dtimen)

#            $ dtime_number = (dtime%6)
#            $ dtime_name_values = ("Early morning", "Morn", "Midday", "Sunset", "Night", "Late night")
#            $ dtimen = dtime_name_values[dtime_number]

#            imagebutton xalign 0.298 ypos 0:
#                idle "gui/abtn_forward.png"
#                hover "gui/abtn_forward_over.png"
#                action Call("advancetime")

            fixed:

                if dtime < 1 and time_adv == True:
                    imagebutton auto "gui/pocketwatch_timeofdaysunrise_gui_%s.png":
                        xalign 0.01
                        ypos 5
                        action SetVariable("dtime", dtime + 1)

                elif dtime < 1 and time_adv == False:
                    imagebutton auto "gui/pocketwatch_timeofdaysunrise_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()

                elif dtime >= 1 and dtime < 2 and time_adv == True:
                    imagebutton auto "gui/pocketwatch_timeofdaymidday_gui_%s.png":
                        xalign 0.01
                        ypos 5
                        action SetVariable("dtime", dtime + 1)

                elif dtime >= 1 and dtime < 2 and time_adv == False:
                    imagebutton auto "gui/pocketwatch_timeofdaymidday_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()

                elif dtime >= 2 and dtime < 3 and time_adv == True:
                    imagebutton auto "gui/pocketwatch_timeofdayevening_gui_%s.png":
                        xalign 0.01
                        ypos 5
                        action SetVariable("dtime", dtime + 1)

                elif dtime >= 2 and dtime < 3 and time_adv == False:
                    imagebutton auto "gui/pocketwatch_timeofdayevening_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()

                elif dtime >= 3 and dtime < 4 and time_adv == True:
                    imagebutton auto "gui/pocketwatch_timeofdaynight_gui_%s.png":
                        xalign 0.01
                        ypos 5
                        action SetVariable("dtime", dtime + 1)

                elif dtime >= 3 and dtime < 4 and time_adv == False:
                    imagebutton auto "gui/pocketwatch_timeofdaynight_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()
#                        action Jump("sleep_now_captains_bed_1")

                elif dtime >= 4:
                    imagebutton auto "gui/pocketwatch_timeofdaynight_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()

#                textbutton _("{b}{color=#C0C0C0}{size=-20}[day]{/size}{/color}{/b}") xalign 0.04 ypos 33
                textbutton daynumber_str xalign 0.04 ypos 33
#                textbutton _("{color=#C0C0C0}{size=-24}[dayn] [dtimen]{/size}{/color}") xalign 0.02 ypos 90
                textbutton daytime_str xalign 0.02 ypos 90
#                textbutton _("{color=#C0C0C0}{size=+24}[dtime]{/size}{/color}") xalign 0.5 ypos 90






#    Show("stats"), Show("booty"), Show("location")




screen no_time_adv_hud():

    vbox:
        fixed:
            imagebutton xalign 1.0 ypos 5:
                idle "gui/ships_log_cover_idle.png"
                hover "gui/ships_log_cover_hover.png"
                action [Show("shipslog_hud"), Hide("no_time_adv_hud")]# Show("statpage_hud") ##, Show("statshide_hud")

            imagebutton xalign 0.01 ypos 990:
                idle "gui/treasure_chest_closed_gui_idle.png"
                hover "gui/treasure_chest_closed_gui_hover.png"
                action [Show ("booty2_hud"), Hide("no_time_adv_hud")]

            imagebutton auto "gui/map_closed_%s.png":
                xalign 0.99
                ypos 875
                action [Show("location2_hud"), Hide("no_time_adv_hud")]

            $ day_number = (day%7)
            $ day_name_values = ("Wed", "Thur", "Fri", "Sat", "Sun", "Mon", "Tue")
            $ dayn = day_name_values[day_number]

            $ dtime_number = (dtime%5)
            $ dtime_name_values = ("Morn", "Midday", "Sunset", "Night", "Nocturn")
            $ dtimen = dtime_name_values[dtime_number]

            $ daynumber_str = __("{color=#C0C0C0}{size=-20}%s{/size}{/color}") % (day)

            $ daytime_str = __("{color=#C0C0C0}{size=-24}%s %s{/size}{/color}") % (dayn, dtimen)

#            $ dtime_number = (dtime%6)
#            $ dtime_name_values = ("Early morning", "Morn", "Midday", "Sunset", "Night", "Late night")
#            $ dtimen = dtime_name_values[dtime_number]

#            imagebutton xalign 0.298 ypos 0:
#                idle "gui/abtn_forward.png"
#                hover "gui/abtn_forward_over.png"
#                action Call("advancetime")

            fixed:

                if dtime < 1:
                    imagebutton auto "gui/pocketwatch_timeofdaysunrise_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()
#                        action SetVariable("dtime", dtime + 1)

                if dtime > 0 and dtime < 2:
                    imagebutton auto "gui/pocketwatch_timeofdaymidday_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()
#                        action SetVariable("dtime", dtime + 1)

                if dtime > 1 and dtime < 3:
                    imagebutton auto "gui/pocketwatch_timeofdayevening_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()
#                        action SetVariable("dtime", dtime + 1)

                if dtime > 2:
                    imagebutton auto "gui/pocketwatch_timeofdaynight_gui_noadv_%s.png":
                        xalign 0.01
                        ypos 5
                        action NullAction()
#                        action Jump("sleep_now_captains_bed_1")

                textbutton _("{b}{color=#C0C0C0}{size=-20}[day]{/size}{/color}{/b}") xalign 0.043 ypos 33
                textbutton _("{color=#C0C0C0}{size=-24}[dayn] [dtimen]{/size}{/color}") xalign 0.02 ypos 90
#                textbutton _("{color=#C0C0C0}{size=+24}[dtime]{/size}{/color}") xalign 0.5 ypos 90






#    Show("stats"), Show("booty"), Show("location")






screen shipslog_hud():

    imagebutton auto "gui/clear_overlay_%s.png":
        xalign 0.5
        yalign 0.5
        action NullAction()

    default flag_var = False # default value of screen variable

#    add 'ships_log_opening_anim_1' # show your animation
    add 'ships_log_contents'

    if not flag_var:
        timer 1.35 action SetScreenVariable("flag_var", True) repeat False

    else: # show some buttons


#        fixed:
#        imagebutton auto "gui/clear_overlay_%s.png":
#            xalign 0.5
#            yalign 0.5
#            action NullAction()
#
#        add "ships_log_opening_anim_1" #(delay = 5)

#        imagebutton auto "gui/ships_log_inside_%s.png":
#            xalign 0.5
#            yalign 0.5
#            action NullAction()
#        textbutton _("[name]") text_color "#000000" text_hover_color "#980002" xpos 550 ypos 150 action ui.callsinnewcontext ("call_panstat")

        vbox:
            xalign 0.5 ypos 905
            textbutton "Close":
                text_color "#000000"
                text_hover_color "#ffffff"
                action [Hide("shipslog_hud"), SetVariable ("ships_log_contents_open", True), SetVariable ("ships_log_inner_pages_forward", True), Hide("statpage_hud"), Hide ("panstats"), Hide ("brittastats"), Hide ("sagastats"), Hide ("signestats"), Hide ("ranstats"), Hide ("katyastats"), Hide ("catstats"), Show("hud")]#, Hide("statshide")

        vbox:
            textbutton "Character Stats":
                text_color "#000000"
                text_hover_color "#c8ffc8"
                xpos 450 ypos 150
                action [Hide("shipslog_hud"), Show ("statpage_hud")] #ui.callsinnewcontext ("call_panstat")

#        vbox:
#            textbutton "Pass":
#                text_color "#000000"
#                text_hover_color "#c8ffc8"
#                xpos 450 ypos 225
#                action [Hide("shipslog_hud"), Jump("code")]



screen statshide_hud():

    vbox:
        xalign 0.5 ypos 905
        textbutton "Close":
            text_color "#000000"
            text_hover_color "#ffffff"
            action [Hide("statpage"), Hide ("panstats"), Hide ("brittastats"), Hide ("sagastats"), Hide ("signestats"), Hide ("ranstats"), Hide ("katyastats"), Hide ("catstats"), Hide("statshide_hud"), Show("hud")]




screen booty2_hud():


    fixed:

        $ money_string = format_money(money)

        imagebutton auto "gui/clear_overlay_%s.png":
            xalign 0.5
            yalign 0.5
            action NullAction()
        if money <= 0: # no money :-( money_string
            imagebutton auto "gui/treasure_chest_open_gui_1_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show ("hud"), Hide ("booty2_hud")]
        elif money > 0 and money < 5000: # $1 -> $4,999
            imagebutton auto "gui/treasure_chest_open_gui_2_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show ("hud"), Hide ("booty2_hud")]
        elif money > 4999 and money < 25000: # $5,000 -> $24,999
            imagebutton auto "gui/treasure_chest_open_gui_3_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show ("hud"), Hide ("booty2_hud")]
        elif money > 24999 and money < 100000: # $25,0000 -> $99,999
            imagebutton auto "gui/treasure_chest_open_gui_4_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show ("hud"), Hide ("booty2_hud")]
        elif money >= 100000: # $100,000+ NEED TO MAKE AT LEAST ONE MORE IMAGE FOR MORE
            imagebutton auto "gui/treasure_chest_open_gui_5_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show ("hud"), Hide ("booty2_hud")]
        textbutton _("{color=#000000}{size=+20}[money_string]{/size}{/color}") xalign 0.5 yalign 0.29   #textbutton _("{color=#000000}{size=+20}$[money]{/size}{/color}") xalign 0.5 yalign 0.29



screen location2_hud():

    $ location_number = (location%4)
    $ location_name_values = ("Universitetö", "At Sea", "Ránsö", "Unknown")
    $ locationn = location_name_values[location_number]



    vbox:
        fixed:
            imagebutton auto "gui/clear_overlay_%s.png":
                xalign 0.5
                yalign 0.5
                action NullAction()
            imagebutton auto "gui/map_open_%s.png":
                xalign 0.5
                yalign 0.5
                action [Show("hud"), Hide("location2_hud")]
            textbutton _("{color=#000000}[locationn]{/color}") xalign 0.48 ypos 535



Last edited by RVNSN on Sun Dec 05, 2021 3:59 am, edited 1 time in total.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Information in hud screens not autorefreshing

#2 Post by zmook »

Maybe you need a `renpy.restart_interaction()` in the code that updates `money` or `location`? That forces renpy to update and redraw all screens, I believe.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
RVNSN
Regular
Posts: 36
Joined: Mon Apr 08, 2019 3:54 pm
Projects: Lust & Piracy
itch: rvnsn
Contact:

Re: Information in hud screens not autorefreshing

#3 Post by RVNSN »

zmook wrote: Sat Nov 27, 2021 2:32 pm Maybe you need a `renpy.restart_interaction()` in the code that updates `money` or `location`? That forces renpy to update and redraw all screens, I believe.
thank you for the suggestion - looking into it, have not had any success experimenting with yet

do you have a suggestion for how to apply it? maybe i'm doing it wrong (probably)

and are you talking about adding in places such as:

Code: Select all

$ money -= 35000
$ money_string = format_money(money)
i tried adding it to the screen action that calls the screen that displays the value, but it did not fix the issue

User avatar
RVNSN
Regular
Posts: 36
Joined: Mon Apr 08, 2019 3:54 pm
Projects: Lust & Piracy
itch: rvnsn
Contact:

Re: Information in hud screens not autorefreshing

#4 Post by RVNSN »

SOLVED!

Resulting from a discussion on another site where I asked about this, the answer ended up being to update renpy. Two or three updates ago (that I did, not that were available), it broke some of my code, and once I realized that I stopped updating. The version I stopped at was 7.4.8.1895, now updated to 7.4.11.2266, and it works again.

Post Reply

Who is online

Users browsing this forum: piinkpuddiin