How to show both AnimatedValue AND the value that's changing?

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
newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

How to show both AnimatedValue AND the value that's changing?

#1 Post by newbiemate »

I have bar that renders a player's health. I would like to animate a healing spell, but also show the current health integer value as it increases. The speed at which the health increases is 2 seconds (for now).

Below I have the code that uses AnimatedValue(), and I also have a text that displays the health:

Code: Select all

screen tryme:
    bar:
        value AnimatedValue(health, 100, 2)                  # Animate the health from 20 -> 100 in 2 seconds   (doesn't work)
        range(100)                                           # Maximum value is 100
        xysize(300,5)
        xpos 300
        ypos 200
        
    text ""+str(health) xpos 350 ypos 250 size 20
    
label start:
    default health = 20 
    show screen tryme
    
    $ renpy.pause(10000)
But there are two issues:

1. The healthbar is still sitting at value 20, it is not animating at all to 100 over 2 seconds.
2. The health integer value is still at 20. I would like to see this value increase as the healthbar increases.

What am I doing wrong?

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#2 Post by gas »

I like humble people that try to make an RPG before reading the docs XD. They dare face the unknown for passion.
...anyway there wasn't a single correct line.

Code: Select all

screen tryme():
    bar:
        value AnimatedValue(value=health, range=100, delay=2.0) 
        # range 100 <<< No need for it in that case, you stated the range in the function above 
        xysize (300,5)
        xpos 300
        ypos 200
        
    text "[health]" xpos 350 ypos 250 size 20 # You can interpolate numbers the same inside texts.

default health = 20 # <<< DEFAULT go there, out of labels!
    
label start:
    # default health = 20   <<< AAAARGH! What's that!?!?!?!?!?!?!?!?!
    show screen tryme
    e "Now I have 20 energy..."
    $ health = 100 # If you don't change the value to 100, how can renpy knows?
    e "... and NOW 100!"
    e "Waiting..."
That 100 in the AnimatedValue is the range, not the score to reach (or you can't change the value more than once, right?).

Now you can freely change the health and see the value automatically change in the interface like any other good RPG around, just using

Code: Select all

$ health = 25 # or any other value you want for.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#3 Post by Milkymalk »

An example like this should go in the docs, because to be honest, I've been trying to get an AnimatedValue to work for years. Partly because it takes "value" as an argument, suggesting that it's a one-time animation from old_value to value.

Is there a way to plug a function as an argument, say, for "delay", so that going from 90 to 100 doesn't take as long as going from 0 to 100? I assume I'd need to pickle the function, yet another thing I never fully understood.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#4 Post by hell_oh_world »

i guess you can always just use conditions...

Code: Select all

AnimatedValue(value=health, range=100, delay=(1.0 if 100 - health <= 10 else 2.0)) 

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#5 Post by gas »

Milkymalk wrote: Fri May 29, 2020 10:31 am Is there a way to plug a function as an argument, say, for "delay", so that going from 90 to 100 doesn't take as long as going from 0 to 100? I assume I'd need to pickle the function, yet another thing I never fully understood.
I can't quite test it right now, but I SUPPOSE you can use a formula...

Code: Select all

bar value AnimatedValue(value = hp, range = 100, delay = (100-hp)/50)
So the less the difference, the less the delay. I can't predict for the lenght of the delay, I think they are just magic numbers (you do the math, in this case is 2 seconds the entire bar, 1 second just half and so on).
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#6 Post by Milkymalk »

This sadly gives a "division by zero" from renpy's internal workings :( But it is possible to give it a variable and change the variable before changing the value variable.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

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

Re: How to show both AnimatedValue AND the value that's changing?

#7 Post by philat »

re: division by zero: use floats, not integers (integer division in python 2.7 would result in 0).

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: How to show both AnimatedValue AND the value that's changing?

#8 Post by gas »

philat wrote: Fri May 29, 2020 10:31 pm re: division by zero: use floats, not integers (integer division in python 2.7 would result in 0).
Mmmm.... no, floats can be prone to division by 0 errors too.

It throw an error even by using floats in some circumstance (like passing from value 50 to value 100). It's how the core function compute the delay by parsing the parameter with multiple divisions and update it.
You should compute the actual delay in advance.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: No registered users