Ren'Py Button Flickers When Timer is Added

tutankhamon

New Member
Nov 4, 2022
5
0
I've checked similar flicker issues in the forum but I couldn't fix my issue with them.
My imagebutton flickers when following screen is shown:

JavaScript:
screen value:
    zorder 1

    vbar:
        value  AnimatedValue(barval, 100, 0.1)
        xalign 0.5
        ymaximum 300

    bar:
        value  AnimatedValue(timebarval, 100, 0.1)
        xalign 0.5
        yalign 0.7
        xmaximum 300
    key "K_SPACE" action If(barval <= 46, true = SetVariable("barval", (barval + 6)), false = NullAction())
And this is the button's script
JavaScript:
screen HUD:
    zorder 10
    imagebutton auto "map_%s":
        focus_mask True
        hovered SetVariable("screen_tooltip", "Map")
        unhovered SetVariable("screen_tooltip", "")
        action Call("map_screen")
I have a timer script as well but when I comment it out, the flicker continues.

This is the timer's script (credits to the anne O'nymous , post -> https://f95zone.to/threads/how-to-interval-timer.11650/). Note that flicker persists even if this code is not active.
JavaScript:
init python:
    intervalCounter = 0
    def myTimer():
        store.intervalCounter += 9
        if intervalCounter < 10:
            return
        store.intervalCounter = 0
        store.timebarval -= 1
        if store.barval > 0:
            store.barval -= 2
        renpy.restart_interaction()
So, can you guys help me?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,299
15,165
This is the timer's script (credits to the anne O'nymous , post -> https://f95zone.to/threads/how-to-interval-timer.11650/).
Hmm, it don't regard directly your issue, but it's seriously outdated. It would be better to rely directly on timer (second part of the post) than on the periodic callback.


Now, for the flickering issue, I guess that it's a refreshing issue.

My first thought regarding the culprit would be for the callback timer (it restart the interaction, and therefore refresh the screen). But you said that it happen even when it's not active, so it's something else that is refreshing the screen.

This being said, the solution is probably to use tooltip in place of hovered/unhovered. It's highly possible that the flickering happen when Ren'Py switch between the two at the creation of the imagebutton. Therefore, replacing it should solve the issue ; and at worse it would still make the code a bit easier.

Python:
    imagebutton auto "map_%s":
        focus_mask True
        tooltip "Map"
        action Call("map_screen")

[...]
    $ tooltip = GetTooltip()
    if tooltip:
        text "[tooltip]"  # Will display "Map" only when the imagebutton is overed.
[/icode]
I haven't fully recovered from the holidays, so I don't guaranty it at 100% but normally [icode]GetTooltip()[/icode] is independent of the screen.
 
  • Like
Reactions: tutankhamon

tutankhamon

New Member
Nov 4, 2022
5
0
Thanks for your reply.
I've removed hovered / unhovered and added tooltip but flickering continued (tooltip text flickered too).

When the following code is added:
JavaScript:
timer 1 repeat True action SetVariable( "timebarval", timebarval - 1 )
and old timer removed, button flickered every 1 second.

I think timer restarts interaction somehow? Can I disable that? Or can I make my buttons unaffected by restart interaction?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,299
15,165
I think timer restarts interaction somehow? Can I disable that? Or can I make my buttons unaffected by restart interaction?
It do, but you can't disable it, because it's this restarts that update the screen and make it show accurate values. And you can't either make the button unaffected.

But this isn't normal. There's a reason behind this behavior on refresh, and it's what have to be solved. From the code you gave, it's a basic button, shown on a basic screen, and it shouldn't do that ; I'll even go further, it don't do that when I try the code.
So there's something else, either a transition on the screen, or a transform on the button, that generate this behavior.