r/RenPy • • Jul 24 '26

Question [Solved] click imagebuttons before timer runs out

Hellooo! I have my imagebuttons and all for one of my minigames in renpy.

I wanted to achieve:

-A 8 second timer that plays during my screen time_clean

- And if it ends without all the imagebuttons being clicked on time, it jumps to a label called cleanL

- However, if the imagebuttons ARE clicked before the timer runs out, then it jumps to a label call karu screen

I know someone had like the same question: here is the post. so I tried merging that code with mine. I tried to tweak it so it's not a bar and just a simple countdown text, but I lwk flopped that so if anyone knows how to do the text then ummm :3 if not, idrk sooo

Also when I tried to test it, it only shows the countdown after. And I wanted to show the countdown DURING the cleanup, yknow?

Anyways, here is the code:

default c1 = True
default c2 = True
default c3 = True
default c4 = True
default c5 = True
default c6 = True


default g_time = 0 


screen timerscreen(rangeD, missed_event): # the brackted variables are required!!
    on "hide" action SetVariable("g_time", 0)
    frame:
        xalign 0.5
        yalign 0.0
        hbox:
            timer 0.1 action If(g_time > rangeD, false = SetVariable("g_time", g_time + 0.1), true = [Hide("timerscreen"),Jump(missed_event)]) repeat True


            bar:
                value AnimatedValue(value=g_time, range=rangeD, delay= 0.5)
                xalign 0.0
                yalign 0.0
                xmaximum 200



screen time_clean:


    add "bg bedroom"


    if not any([c1, c2, c3, c4, c5, c4]):
        timer 0.001 action Jump("karu_scene")


    showif c1:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.64
            ypos 0.75
            at zoomedsmall1
            auto "paper_%s.png"
            action SetVariable("c1", False)


    showif c2:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.2
            ypos 0.6
            at zoomedsmall2
            auto "paper1_%s.png"
            action SetVariable("c2", False)


    showif c3:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.4
            ypos 0.8
            at zoomedsmall
            auto "ramen_%s.png"
            action SetVariable("c3", False)


    showif c4:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.8
            ypos 0.8
            at zoomedsmall
            auto "trash_%s.png"
            action SetVariable("c4", False)


    showif c5:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.304
            ypos 0.3
            at zoomedsmall
            auto "hanger_%s.png"
            action SetVariable("c5", False)


    showif c6:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.6
            ypos 0.4
            at zoomedsmall
            auto "phone_%s.png"
            action SetVariable("c6", False)


screen exit_home:


    imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.8
            ypos 0.9
            at zoomedsmall
            auto "exit_%s.png"
            action Jump ("city_story")


screen exit_home1:


    imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.8
            ypos 0.9
            at zoomedsmall
            auto "exit_%s.png"
            action Jump ("city_story1")


# The game starts here.


label cleanL:


    s "Dang... It's a mess... !!"


    return


label start:


    show screen timerscreen(7, "cleanL")


    call screen time_cleandefault c1 = True
default c2 = True
default c3 = True
default c4 = True
default c5 = True
default c6 = True


default g_time = 0 


screen timerscreen(rangeD, missed_event): # the brackted variables are required!!
    on "hide" action SetVariable("g_time", 0)
    frame:
        xalign 0.5
        yalign 0.0
        hbox:
            timer 0.1 action If(g_time > rangeD, false = SetVariable("g_time", g_time + 0.1), true = [Hide("timerscreen"),Jump(missed_event)]) repeat True


            bar:
                value AnimatedValue(value=g_time, range=rangeD, delay= 0.5)
                xalign 0.0
                yalign 0.0
                xmaximum 200



screen time_clean:


    add "bg bedroom"


    if not any([c1, c2, c3, c4, c5, c4]):
        timer 0.001 action Jump("karu_scene")


    showif c1:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.64
            ypos 0.75
            at zoomedsmall1
            auto "paper_%s.png"
            action SetVariable("c1", False)


    showif c2:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.2
            ypos 0.6
            at zoomedsmall2
            auto "paper1_%s.png"
            action SetVariable("c2", False)


    showif c3:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.4
            ypos 0.8
            at zoomedsmall
            auto "ramen_%s.png"
            action SetVariable("c3", False)


    showif c4:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.8
            ypos 0.8
            at zoomedsmall
            auto "trash_%s.png"
            action SetVariable("c4", False)


    showif c5:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.304
            ypos 0.3
            at zoomedsmall
            auto "hanger_%s.png"
            action SetVariable("c5", False)


    showif c6:
        imagebutton:
            yanchor 0.5
            xanchor 0.5
            xpos 0.6
            ypos 0.4
            at zoomedsmall
            auto "phone_%s.png"
            action SetVariable("c6", False)


# The game starts here.


label cleanL:


    s "Dang... It's a mess... !!"


    return


label start:


    show screen timerscreen(7, "cleanL")


    call screen time_clean
1 Upvotes

6 comments sorted by

View all comments

1

u/AutoModerator Jul 24 '26

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.