Resetting a bar's value

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
User avatar
akemicchi
Veteran
Posts: 465
Joined: Mon Dec 31, 2007 11:22 pm
Projects: Magicians of Delphine, Panaderia: Ensaimada, SweetTooth!, XOXO Droplets
Deviantart: littlebabyshoes
Contact:

Resetting a bar's value

#1 Post by akemicchi »

So I want something like A Dark Room...
http://adarkroom.doublespeakgames.com/

There's a button on screen. If the player clicks it, a bar appears and takes x amount of time to fill up. When the bar is full, something happens and the bar disappears.

I want multiple buttons on the screen. The player can click on multiple buttons. That means multiple bars showing up on the screen all getting filled at different rates. I figure the best way to do this is have a 'for' loop, use a class/list/dictionary/something to store all the data, and have it 'use' a screen only containing the bar. No problem. The problem I'm having with this is that once the player clicks the button, the bar (using AnimatedValue) remains filled.

How would I reset the bar so the value stored is 0 again?

I figured out I can get it to reset by showing and hiding the screen, but it looks really clunky and needs me to make multiples of the same screen. Not to mention I'll have to position it manually instead of having the bar nestled right next to button in an hbox...

What I have so far:

Code: Select all

screen baking():
    frame:
        align (0.05, 0.05)
        xpadding 10 ypadding 10
        xfill True yfill True
        xysize (150, 200)
        
        vbox:
            textbutton "Bread" action [Show("bread_bar", time=3, text="Baked Bread!", hide_screen="bread_bar")]
            textbutton "Cake" action [Show("cake_bar", time=10, text="Baked Cake!", hide_screen="cake_bar")]

screen bread_bar(time, text, hide_screen):
    use item_bar(time, text, hide_screen)

screen cake_bar(time, text, hide_screen):
    use item_bar(time, text, hide_screen)

screen item_bar(time, text, hide_screen):
    timer time action [ItemLog(text), Hide(hide_screen)]
    bar value AnimatedValue(200, 200, time, 0): # This here?
        xysize (200,25)
        thumb None
Anyone know a better way of doing this? I'd really appreciate the help! I'm also wondering if it's possible to have a bar that works like in A Dark Room? When the button is clicked, the bar appears behind the button and fills up there.

Thanks so much for your time! :)

Shaples
Regular
Posts: 84
Joined: Sat Sep 27, 2014 2:08 pm
Completed: Christmas Sweaters
Projects: White Lie, Tropichu!
Contact:

Re: Resetting a bar's value

#2 Post by Shaples »

I don't have an answer for you, but I just wanted to let you know that I read your post and went "what's A Dark Room?" And clicked on your link and the next thing I knew it was 6 in the morning and I'd been clicking buttons for hours. So, thank you :D

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Resetting a bar's value

#3 Post by philat »

Can you post the code for how you were doing it before? I'm not sure exactly how you set it up and what you mean by the bar would stay full.

User avatar
akemicchi
Veteran
Posts: 465
Joined: Mon Dec 31, 2007 11:22 pm
Projects: Magicians of Delphine, Panaderia: Ensaimada, SweetTooth!, XOXO Droplets
Deviantart: littlebabyshoes
Contact:

Re: Resetting a bar's value

#4 Post by akemicchi »

lol, Shaples... Glad you enjoyed playing it, though. It really is addicting!

I don't remember my code, but it went something along the lines of:

Code: Select all

    textbutton "Bread" action [SetVariable("bread_bar", True)]
    if bread_bar == True:
        bar value AnimatedValue(200, 200, 3, 0)
        timer 3 action [FunctionHere(), SetVariable("bread_bar", False)]
    else:
        null
After running once, the bar remains full when shown again. That's really as simply as I can put it. It doesn't reset to a value of 0 and animate to 200 after running once. It appears to store the new value.
bars.png
bars.png (697 Bytes) Viewed 924 times
Left is an empty bar. Right is a full bar. It starts out empty then ends up full after a period of time.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Resetting a bar's value

#5 Post by philat »

Code: Select all

python:
    Bread_bar = False
    Cake_bar = False
    Bread_time = 3
    Cake_time = 10

screen baking():
    frame:
        align (0.05, 0.05)
        xpadding 10 ypadding 10
        xfill True yfill True
        xysize (150, 200)
        
        vbox:
            textbutton "Bread" action [SensitiveIf(Bread_bar == False), ToggleVariable("Bread_bar", true_value=True, false_value=False), Function(renpy.restart_interaction)]
            if Bread_bar:
                timer 0.01 repeat True action If(Bread_time > 0, true=SetVariable('Bread_time', Bread_time - 0.01), false=[SetVariable("Bread_bar", False), SetVariable("Bread_time", 3)])
                bar value Bread_time range 3:
                    thumb None
Perhaps something like this? It's a bit more messy than using AnimatedValue, but it works. (I didn't bother inverting the thing, but you can invert it easily.)

General idea from http://lemmasoft.renai.us/forums/viewto ... =8&t=25114

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Resetting a bar's value

#6 Post by PyTom »

I'd suggest putting the bread bar on its own screen, and showing/hiding that screen.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Toma