[Solved] Screen with timer doesn't 'hide' properly

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
goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

[Solved] Screen with timer doesn't 'hide' properly

#1 Post by goldo » Sun Jul 26, 2020 4:50 pm

Hi guys,

Ok, this one is tough but I'd like to give it a shot.

I have a screen called 'trait_details' that is displayed when hovering over a 'Trait' button, and hidden when unhovering, similar to a tooltip screen.

Depending on how many 'traits' there are, the content is sometimes too long for the screen.

So what I want to create is a screen that slowly scrolls down on its own when it's too long, similar to some games. (Think about the star wars intro text effect, without the perspective). I used a viewport and a ui.adjustment(), and I managed to do just that:

Code: Select all

## TRAITS LIST ##
textbutton "Traits":
                    action NullAction()
                    hovered Show("trait_details", girl=girl)
                    unhovered Hide("trait_details")
                    
[...]

screen trait_details(girl):

    tag trait_details

    default yadj = ui.adjustment()
    default t = 0

    if len(girl.traits) > 12:
        timer 0.01 repeat True action (SetScreenVariable("t", t + 0.01), Function(yadj.change, max(0, 100*(t-0.1))))

    frame:
        background c_ui_darker
        xalign 0.5
        yalign 0.8
        xsize int(config.screen_width / 2.8)
        ymaximum int(config.screen_height*0.8)

        viewport:
            	yadjustment yadj
            	
            	has vbox spacing 3

                text girl.name + "'s traits"
                
                for trait in girl.traits:
                	hbox:
                    		text trait.name
                    		text trait.get_description()

		[...]
                    
Now this code almost works as intended. Hovering on the 'Traits' button shows a screen that slowly scrolls down after 0.1 seconds, if there is too much text.

The problem is that when one moves the mouse away from the Trait button, the screen stays shown until the scrolling animation is complete, ignoring this part of the code:
unhovered Hide("trait_details")
This doesn't happen when the length of the trait list is shorter (and the timer is off): the screen hides immediately upon unhovering.

Do you guys know how to enforce the 'Hide' command on a screen that has a timer when unhovering? Is there a different approach that works to get the same behavior? Thank you for reading!
Last edited by goldo on Mon Jul 27, 2020 6:19 pm, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Screen with timer doesn't 'hide' properly

#2 Post by hell_oh_world » Sun Jul 26, 2020 6:54 pm

0.01 delay for repeated timers causes issues around screens. Like the atl lagging or the screen not responding, as every execution of the action the interaction is restarted. 0.02 and above should be an okayish value for repeated actions, though restart interaction is inevitable. You might as well want to add another condition that would tell the timer to stop when the scroll value is max because the action continues to run i think even after the scroll value is maxed. In the end, i would suggest doing this effect using a custom displayable, i've seen games that do use that method, another thing would be the AnimatedValue() action, i think that does the trick when it comes to bars, and viewports can have bars so that might work. Although, i havent worked with it a bit.

goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Screen with timer doesn't 'hide' properly

#3 Post by goldo » Mon Jul 27, 2020 6:19 pm

Thank you, I had to reduce the timer to 0.1 to get the desired effect, but it now works! The animation is not very smooth, but that'll do...

Post Reply

Who is online

Users browsing this forum: Google [Bot]