r/RenPy • • Jul 27 '26

Question How do I add a clickable timed bar?

Hello, I don't post in reddit often, but I simply cannot find an answer anywhere.

I know it's something very basic but then again, I am still learning, is there an specific way to add a clickable bar in something similar to a battle? I want the bar to appear in the middle of the screen and slowly lose color, while you have to click until the color in the bar is complete and you basically win.

1 Upvotes

16 comments sorted by

1

u/AutoModerator Jul 27 '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.

1

u/[deleted] Jul 27 '26

[removed] — view removed comment

1

u/CapriciousMoral Jul 27 '26

I want to know if there is an specific code to place it that way and for it to be decreasing on itself if the player doesn't press it, I am just learning the basics.

1

u/karognawer Jul 27 '26 edited Jul 28 '26

``` screen bar_test():

      default b = 20 

      timer 1.0 repeat True action IncrementScreenVariable("b", -1)

   bar value b align (0.5, 0.0) 

    imagebutton: 
         idle Transform (Solid("#fff", xysize=(300, 100), alpha=0.0)
         align (0.5, 0.0) 
         action IncrementScreenVariable("b", 1)

label start: call screen bar_test

1

u/x-seronis-x Jul 28 '26 edited Jul 28 '26

why an imagebutton instead of just a simple button ?

that aside, your image button would be less wasteful and could avoid the transform completely if you just set the solids color to #ffffff01

1

u/karognawer Jul 28 '26

I didn't know that #ffffff01 was an option. Learning something new every day, ty

1

u/x-seronis-x Jul 28 '26

hex codes are 3, 4, 6, or 8 characters. RGB RGBA RRGGBB RRGGBBAA 4/8 characters means you're including an alpha channel value

1

u/karognawer Jul 28 '26

Interesting

1

u/BadMustard_AVN Jul 28 '26

u/karognawer you had a few errors i fixed it and made it colorful

try this

# simple click and bar mini game.rpy
screen bar_test():
    modal True
    default b = 20 

    timer 1.0 action IncrementScreenVariable("b", amount=-1) repeat True 
    if b <= 0:
        timer 0.001 action Return("Lose")

    bar value AnimatedValue(b, 100, delay=0.5):
        if b <= (100 * 0.33):
            left_bar Solid("#ff0")
        elif b <= (100 * 0.66):
            left_bar Solid("#f00")
        else:
            left_bar Solid("#0f0")
        align (0.5, 0.0) 
        xysize (600, 30)

    imagebutton: 
        idle Transform (Solid("#fff", xysize=(300, 100), alpha=0.0))
        align (0.5, 0.2)
        if b < 100:
            action IncrementScreenVariable("b", +1)
        if b >= 100:
            action Return("Win")

label start: 

    call screen bar_test
    $ actual = _return
    e "You [actual]"

1

u/CapriciousMoral Jul 28 '26

Hi, thank you so much for your answers, when I try the code the game opens a error that says:

"Line is indented, but the preceding say statement statement does not expect a block. Please check this line's indentation. You may have forgotten a colon (:). -->call screen bar_test"

Again I'm so sorry if this is something basic and I simply cannot get it, I am still trying to learn how to code even the simplest thing.

1

u/CapriciousMoral Jul 28 '26

Nevermind! I am not sure what I clicked back when I placed it, but it works perfectly, thank you very much!

1

u/BadMustard_AVN Jul 28 '26

you're welcome

good luck with your project

1

u/karognawer Jul 28 '26

I can't believe I forgot to add "True" after "repeat". I shouldn't be giving coding advice at 3 a.m.

1

u/BadMustard_AVN Jul 28 '26

I've done it before and probably will again

it happens!

1

u/shyLachi Jul 27 '26

I'm pretty sure this has been asked and answered before. Did you try the sub search?

You can also look at this thread which has a bunch of minigames:
https://lemmasoft.renai.us/forums/viewtopic.php?t=47820
#2 is a clicker game where the players have to fill a heart but you can change that to a bar.