Ren'Py Having an issue with a HUD "refresh".

Skeltom

Engaged Member
Oct 9, 2017
2,354
2,780
I have my HUD almost set up and one of the imagebutton calls in a function to skip time. It all works as intended except that it doesn't reflect the changes to the hud until I unhover from the button. Do I need to add something else to the code for it to change regardless of the mouse position?

Python:
screen hud():
    modal False
    if Day == 0:
        add "monday"
    if Day == 1:
        add "tuesday"
    if Day == 2:
        add "wednesday"
    if Day == 3:
        add "thursday"
    if Day == 4:
        add "friday"
    if Day == 5:
        add "saturday"
    if Day == 6:
        add "sunday"

    if TimeOfDay == 0:
        add "dawn"
    if TimeOfDay == 1:
        add "morning"
    if TimeOfDay == 2:
        add "afternoon"
    if TimeOfDay == 3:
        add "evening"
    if TimeOfDay == 4:
        add "night"

    imagebutton auto "home_map_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Homestead Map")
        unhovered SetVariable("screen_tooltip", "")
        action Show("homestead_map"), Hide("hud")

    imagebutton auto "area_map_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Area Map")
        unhovered SetVariable("screen_tooltip", "")
        action Show("area_map"), Hide("hud")

    imagebutton auto "stats_button_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Characters")
        unhovered SetVariable("screen_tooltip", "")
        action Show("characters"), Hide("hud")

    imagebutton auto "notes_button_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Journal")
        unhovered SetVariable("screen_tooltip", "")
        action Show("journal"), Hide("hud")

    imagebutton auto "skip_time_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Skip Time")
        unhovered SetVariable("screen_tooltip", "")
        action skiptime
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,174
Do I need to add something else to the code for it to change regardless of the mouse position?
Adding something, no. Doing things correctly, yes.

There's a reason why the screen action exist. And this reason is precisely to ensure that the game context, and therefore screens, are immediately updated following whatever change happened.

And while I'm at it, you should take a look at the .

You can also simplify you screen relatively easily by relying on list instead of long (and wrong) if structures.

Python:
define dayAsString = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ]
define todAsString = [ "dawn", "morning", "afternoon", "evening", "night" ]

screen hud():
    #modal False      <- This is useless, it's the default value.

    add dayAsString[Day]

    add todAsString[TimeOfDay]

    imagebutton auto "home_map_%s":
        focus_mask True
        tooltip "Homestead Map"
        action Show("homestead_map"), Hide("hud")

    imagebutton auto "area_map_%s":
        focus_mask True
        tooltip "Area Map"
        action Show("area_map"), Hide("hud")

    imagebutton auto "stats_button_%s":
        focus_mask True
        tooltip "Characters"
        action Show("characters"), Hide("hud")

    imagebutton auto "notes_button_%s":
        focus_mask True
        tooltip "Journal"
        action Show("journal"), Hide("hud")

    imagebutton auto "skip_time_%s":
        focus_mask True
        tooltip "Skip Time"
        action Function( skiptime )
I don't included the code to display the tooltip, since it isn't in your own code ; therefore I don't know how you want it, nor strictly speaking what the value means.
 

Skeltom

Engaged Member
Oct 9, 2017
2,354
2,780
Adding something, no. Doing things correctly, yes.

There's a reason why the screen action exist. And this reason is precisely to ensure that the game context, and therefore screens, are immediately updated following whatever change happened.

And while I'm at it, you should take a look at the .

You can also simplify you screen relatively easily by relying on list instead of long (and wrong) if structures.

Python:
define dayAsString = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ]
define todAsString = [ "dawn", "morning", "afternoon", "evening", "night" ]

screen hud():
    #modal False      <- This is useless, it's the default value.

    add dayAsString[Day]

    add todAsString[TimeOfDay]

    imagebutton auto "home_map_%s":
        focus_mask True
        tooltip "Homestead Map"
        action Show("homestead_map"), Hide("hud")

    imagebutton auto "area_map_%s":
        focus_mask True
        tooltip "Area Map"
        action Show("area_map"), Hide("hud")

    imagebutton auto "stats_button_%s":
        focus_mask True
        tooltip "Characters"
        action Show("characters"), Hide("hud")

    imagebutton auto "notes_button_%s":
        focus_mask True
        tooltip "Journal"
        action Show("journal"), Hide("hud")

    imagebutton auto "skip_time_%s":
        focus_mask True
        tooltip "Skip Time"
        action Function( skiptime )
I don't included the code to display the tooltip, since it isn't in your own code ; therefore I don't know how you want it, nor strictly speaking what the value means.
EDIT: Never Mind. I got confused and thought I needed to change the function I had already. That's on me. It seems to be working now, thanks.

I was using lists before but I must not have selected them when I posted the code. This is what I was using before and it was working well aside from it not refreshing. I was using ifs to call in images for the string. It's longer but I can see it for myself and it's better for my overall sanity. The tooltip is just something I was playing around with. Not sure how it's "wrong" if it works.

Python:
default Day = ["Monday","Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
default TimeOfDay = ["Dawn", "Morning", "Afternoon", "Evening", "Night"]

screen hud():
    modal False
    if Day == 0:
        add "monday"
    if Day == 1:
        add "tuesday"
    if Day == 2:
        add "wednesday"
    if Day == 3:
        add "thursday"
    if Day == 4:
        add "friday"
    if Day == 5:
        add "saturday"
    if Day == 6:
        add "sunday"

    if TimeOfDay == 0:
        add "dawn"
    if TimeOfDay == 1:
        add "morning"
    if TimeOfDay == 2:
        add "afternoon"
    if TimeOfDay == 3:
        add "evening"
    if TimeOfDay == 4:
        add "night"

    imagebutton auto "home_map_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Homestead Map")
        unhovered SetVariable("screen_tooltip", "")
        action Show("homestead_map"), Hide("hud")

    imagebutton auto "area_map_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Area Map")
        unhovered SetVariable("screen_tooltip", "")
        action Show("area_map"), Hide("hud")

    imagebutton auto "stats_button_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Characters")
        unhovered SetVariable("screen_tooltip", "")
        action Show("characters"), Hide("hud")

    imagebutton auto "notes_button_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Journal")
        unhovered SetVariable("screen_tooltip", "")
        action Show("journal"), Hide("hud")

    imagebutton auto "skip_time_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Skip Time")
        unhovered SetVariable("screen_tooltip", "")
        action skiptime
Python:
init python:

    def skiptime():
        global TimeOfDay
        global Day
        if TimeOfDay <= 3:
            TimeOfDay += 1
        else:
            TimeOfDay = 0
            if Day > 5:
                Day = 0
            else:
                Day += 1
I tried to change the skiptime to the new lists but it gives an error. TypeError: '<=' not supported between instances of 'RevertableList' and 'int'. I'm still new to screens and functions so I likely messed up.

Python:
init python:

    def skiptime():
        global todAsString
        global dayAsString
        if todAsString <= 4:
            todAsString += 1
        else:
            todAsString = 0
            if dayAsString > 5:
                Day = 0
            else:
                dayAsString += 1
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,174
I was using lists before but I must not have selected them when I posted the code.
Ok, let's be clear here:

  • In your second code, the lists and numbers share the same name.
  • In both your codes, you are chaining if in place of using if/elif.
  • You don't understand why your new "skiptime" throw an error, while the error message is relatively obvious.
And you expect me to believe that, by yourself, you came to the use of lists, coupled to a dynamic use of add ? Why are you lying ?

There's no shame in not knowing something. You are here to learn, and we are here to share what we know.
But you'll learn nothing if you starts to lie, because people will talk to you accordingly to the knowledge you pretend to have, and you'll understand nothing they'll say.


Not sure how it's "wrong" if it works.
I haven't said that it was wrong, just that it can be simplified.
And, must be said, your reason to not simplify the code is perfectly legit.


I tried to change the skiptime to the new lists but it gives an error.
No you haven't.
You are surely honest when writing this sentence, but what you did isn't what you think you did.

You awkwardly tried to replicate what you thought you understood after you had a quick look at my post.

Would you had took the time to address my post like a person wanting to learn would have done, you would have noticed something really obvious: the name of the variables.
Will I kept your Day and TimeOfDay counters, the list was named dayAsString and todAsString. And the difference is explicit enough to be noticed ; especially for the first list, that have a name more than three time longer than the equivalent counter.
Then, once you notice this difference, you also more or less understand that there's nothing to change in "skiptime", since at no time it's concerned by the fact that you use lists or not.

You can't know it, but when the code I post is experimental, a rough idea, or will not works whatever the rest of your own code, I always say it explicitly. Hell, I even tend to warn when there's just 1% risk that the code don't works.
This mean that, unless there's an unnoticed typo, you've nothing to change, except the screen itself, for the code I gave to works, period.


But there's something way more important to address here.


The first thing I did in my answer was to solve your issue, and explain how to have your screen works as you want it to works (without having to unhover the button for the change to apply).

And this, it seem evident that you totally missed it.
 

Skeltom

Engaged Member
Oct 9, 2017
2,354
2,780
Ok, let's be clear here:

  • In your second code, the lists and numbers share the same name.
  • In both your codes, you are chaining if in place of using if/elif.
  • You don't understand why your new "skiptime" throw an error, while the error message is relatively obvious.
And you expect me to believe that, by yourself, you came to the use of lists, coupled to a dynamic use of add ? Why are you lying ?

There's no shame in not knowing something. You are here to learn, and we are here to share what we know.
But you'll learn nothing if you starts to lie, because people will talk to you accordingly to the knowledge you pretend to have, and you'll understand nothing they'll say.




I haven't said that it was wrong, just that it can be simplified.
And, must be said, your reason to not simplify the code is perfectly legit.




No you haven't.
You are surely honest when writing this sentence, but what you did isn't what you think you did.

You awkwardly tried to replicate what you thought you understood after you had a quick look at my post.

Would you had took the time to address my post like a person wanting to learn would have done, you would have noticed something really obvious: the name of the variables.
Will I kept your Day and TimeOfDay counters, the list was named dayAsString and todAsString. And the difference is explicit enough to be noticed ; especially for the first list, that have a name more than three time longer than the equivalent counter.
Then, once you notice this difference, you also more or less understand that there's nothing to change in "skiptime", since at no time it's concerned by the fact that you use lists or not.

You can't know it, but when the code I post is experimental, a rough idea, or will not works whatever the rest of your own code, I always say it explicitly. Hell, I even tend to warn when there's just 1% risk that the code don't works.
This mean that, unless there's an unnoticed typo, you've nothing to change, except the screen itself, for the code I gave to works, period.


But there's something way more important to address here.


The first thing I did in my answer was to solve your issue, and explain how to have your screen works as you want it to works (without having to unhover the button for the change to apply).

And this, it seem evident that you totally missed it.
First off, what the fuck is your problem. I came to ask a question and your turning it into a personal attack. I didn't know that answering a question was so personally taxing for you.

I didn't "lie" in any of my responses. I guess I just pulled the codes out of my ass. I'm back to using my old code with the exception of adding the function action from your post and it is fine now, so thanks for that one helpful response.
 
  • Haha
Reactions: anne O'nymous