[SOLVED] Animate variables when they are updated?

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.
Message
Author
OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

[SOLVED] Animate variables when they are updated?

#1 Post by OrsonDeWitt » Fri Sep 18, 2020 3:00 am

Hello experts of Ren'py :)
I've been wondering for a while now about the way I could make a variable on the HUD blink/transform/whatever (for a sec) after the player has a made a choice and the variable has changed? Couldn't find anything on the forums... I'm using menu arguments (to highlight variables that are going to be changed) if that helps.
Any help would be appreciated. Thanks!
Last edited by OrsonDeWitt on Fri Nov 20, 2020 5:35 pm, edited 3 times in total.

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

Re: Animate variables when they are updated?

#2 Post by hell_oh_world » Fri Sep 18, 2020 7:43 am

should be a good example.

Code: Select all

default var = 1

screen something():
  textbutton "increment" action SetVariable("var", var + 1) align (0.5, 0.5)

  text str(var):
    align (0.5, 0.25)

    at animation_update

transform animation_update():
  on update:
    alpha 0.0
    easein 0.25 alpha 1.0
    
label start:
  call screen something

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#3 Post by OrsonDeWitt » Mon Oct 12, 2020 10:13 am

hell_oh_world wrote:
Fri Sep 18, 2020 7:43 am
should be a good example.
Thanks, hell_oh_world! But unfortunately it does not seem to do anything. I've tried different effects and none of them fires, the variable just changes as always does with no effect whatsoever. :/

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#4 Post by OrsonDeWitt » Sun Oct 18, 2020 8:48 am

Still haven't found a solution :(

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

Re: Animate variables when they are updated?

#5 Post by hell_oh_world » Sun Oct 18, 2020 3:00 pm

I don't know what you did. But my code works exactly well iirc. I even tried it before, so maybe you're missing something? Perhaps an issue with the Ren'Py version you're using? Not sure.

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#6 Post by OrsonDeWitt » Tue Nov 17, 2020 4:06 pm

hell_oh_world wrote:
Sun Oct 18, 2020 3:00 pm
I don't know what you did. But my code works exactly well iirc. I even tried it before, so maybe you're missing something? Perhaps an issue with the Ren'Py version you're using? Not sure.
You're right, it works! I was trying to test it like this:

Code: Select all

screen test():
    vbox:
        textbutton "increment" action SetVariable("svar", svar + 1)
        text str(svar):
            align (0.5, 0.25)
            at animation_update
And would never for the life of mine think that vbox would prevent transform from happening. Now that I have deleted it, it works as expected. Why is there such a behavior with vbox? I'm confused...
Thanks a lot for your help!

I have just one problem with this, the animation activates whenever I click or hover over any button (that has a tooltip). I guess "on update" takes the update in Ren'py as a condition, not the update of the variable itself?

User avatar
_ticlock_
Veteran
Posts: 323
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Animate variables when they are updated?

#7 Post by _ticlock_ » Tue Nov 17, 2020 5:03 pm

OrsonDeWitt wrote:
Tue Nov 17, 2020 4:06 pm
And would never for the life of mine think that vbox would prevent transform from happening.
vbox does not prevent transform from happening. It does not work because on update event is not triggered for screen text str(svar). on update event is triggered for direct children of the screen test.
For example, the transform will be triggered in this case (for all children):

Code: Select all

screen test():
    vbox:
        at animation_update
        vbox:
            textbutton "increment" action SetVariable("svar", svar + 1)
            text str(svar):
                align (0.5, 0.25)
However, the transform will not be triggered in this case:

Code: Select all

screen test():
    vbox:
        vbox:
            at animation_update
            textbutton "increment" action SetVariable("svar", svar + 1)
            text str(svar):
                align (0.5, 0.25)

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#8 Post by OrsonDeWitt » Tue Nov 17, 2020 5:22 pm

_ticlock_ wrote:
Tue Nov 17, 2020 5:03 pm
However, the transform will not be triggered in this case:
Why is it triggered whenever I hover over UI elements in HUD screen then...?

User avatar
_ticlock_
Veteran
Posts: 323
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Animate variables when they are updated?

#9 Post by _ticlock_ » Tue Nov 17, 2020 11:14 pm

OrsonDeWitt wrote:
Tue Nov 17, 2020 5:22 pm
Why is it triggered whenever I hover over UI elements in HUD screen then...?
Do you mean on hover and on idle statements in transform? On update is triggered for direct children and each of them updated its content/children without passing on update to each individual element. On hover and on idle statements work differently. They are triggered for elements that gains/loses focus.

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#10 Post by OrsonDeWitt » Wed Nov 18, 2020 10:51 am

_ticlock_ wrote:
Tue Nov 17, 2020 11:14 pm
OrsonDeWitt wrote:
Tue Nov 17, 2020 5:22 pm
Why is it triggered whenever I hover over UI elements in HUD screen then...?
Do you mean on hover and on idle statements in transform? On update is triggered for direct children and each of them updated its content/children without passing on update to each individual element. On hover and on idle statements work differently. They are triggered for elements that gains/loses focus.
No, I use the code of hell_oh_world in a separate screen while I also have HUD screen on top that is opened by clicking a button. So whenever I "open" HUD and whenever I hover over any of its elements (textbuttons and imagebuttons), the code of hell_oh_world gets activated and the blinking happens even though the variable is not being updated.

User avatar
_ticlock_
Veteran
Posts: 323
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Animate variables when they are updated?

#11 Post by _ticlock_ » Wed Nov 18, 2020 12:44 pm

'On update' is triggered every time the screen is updated. It is not directly related to the variable svar or the screen 'test' itself. HUD screen can also trigger 'on update' for screen 'test'.

I am not quite sure why it is triggered when you hover over elements of HUD screen. I believe you have an action, that is run when the element gains focus. That can result in triggering 'on update' as well.

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#12 Post by OrsonDeWitt » Thu Nov 19, 2020 1:55 pm

_ticlock_ wrote:
Wed Nov 18, 2020 12:44 pm
'On update' is triggered every time the screen is updated. It is not directly related to the variable svar or the screen 'test' itself. HUD screen can also trigger 'on update' for screen 'test'.

I am not quite sure why it is triggered when you hover over elements of HUD screen. I believe you have an action, that is run when the element gains focus. That can result in triggering 'on update' as well.
Does it mean that there is no way to do what I had described in the post?
Here's how my imagebuttons that open HUD are defined:

Code: Select all

            idle "Gods_screen.png" action Hide("gods_screen", transition=dissolve)
           idle "Gods_screen.png" action Show("gods_screen", transition=dissolve)

User avatar
_ticlock_
Veteran
Posts: 323
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Animate variables when they are updated?

#13 Post by _ticlock_ » Thu Nov 19, 2020 4:31 pm

Am I right that you want the transform to happen only when the variable svar is changed? And not when you click on other elements that can result in 'update' event of the screen?

One option to do it is to use another variable to track if svar is changed. You can modify your screen test like this:

Code: Select all

screen test():
    default update_svar = False
    textbutton "increment" action SetVariable("svar", svar + 1), SetScreenVariable("update_svar", True)
    if update_svar:
        $ update_svar = False
        text str(svar):
            align (0.5, 0.25)
            at animation_update
    else:
        text str(svar):
            align (0.5, 0.25)

Screen variable update_svar tracks if you need to apply transform animation_update or not.

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

Re: Animate variables when they are updated?

#14 Post by hell_oh_world » Fri Nov 20, 2020 1:21 pm

Alternatively, you can just do this, short but a neat trick, passing variables around atl makes them dynamic on each interaction restart.

Code: Select all

transform animation_update(var): # make an argument where we can receive the variable.
    alpha 0.0
    easein 0.25 alpha 1.0

default var = 1

screen something():
    vbox:
        align (0.5, 0.25)
        
        textbutton "increment" action SetVariable("var", var + 1) align (0.5, 0.5)
        
        text str(var):
            at animation_update(var) # then just pass the var for no reason...
            
Last edited by hell_oh_world on Fri Nov 20, 2020 1:24 pm, edited 1 time in total.

OrsonDeWitt
Regular
Posts: 34
Joined: Thu Dec 06, 2018 3:23 am
Contact:

Re: Animate variables when they are updated?

#15 Post by OrsonDeWitt » Fri Nov 20, 2020 1:23 pm

_ticlock_ wrote:
Thu Nov 19, 2020 4:31 pm
Am I right that you want the transform to happen only when the variable svar is changed? And not when you click on other elements that can result in 'update' event of the screen?

One option to do it is to use another variable to track if svar is changed. You can modify your screen test like this:

Code: Select all

screen test():
    default update_svar = False
    textbutton "increment" action SetVariable("svar", svar + 1), SetScreenVariable("update_svar", True)
    if update_svar:
        $ update_svar = False
        text str(svar):
            align (0.5, 0.25)
            at animation_update
    else:
        text str(svar):
            align (0.5, 0.25)

Screen variable update_svar tracks if you need to apply transform animation_update or not.
Ah, amazing! Thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], JimPanse, Valhalla Ent