Ren'Py Translate state in python

Sagisu

Newbie
Nov 12, 2017
30
25
Hey there, It's again me with 'I want to complicate life for myself' question =)
So currently I'm passing a transform function to change some states of buttons, but I'd like to add some life to it, so I was wondering if there is possibility to add like in regular ATL block something like idle or hover states with easing animation? I mean, how can I do this:
Code:
transform some_button():
    on idle:
        easein 0.9 xpos 0
    on hover:
        easein 0.5 xpos -60
Into this:
Code:
transform some_button():
    function test_fn()

init python:
    def test_fn(tf,st,at):
         # how to modify tf object?
         return 0
I know I can calculate it manually, but I'm wondering if there is some out-of-the-box solution and how can I get current state of the element (eg. hovered or selected)? Source code says there's a arguments field in Transform class, that should have those states, but for me it's constantly empty.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,490
7,035
Hey there, It's again me with 'I want to complicate life for myself' question =)
So currently I'm passing a transform function to change some states of buttons, but I'd like to add some life to it, so I was wondering if there is possibility to add like in regular ATL block something like idle or hover states with easing animation? I mean, how can I do this:
I'm not 100% sure, but looking at your code, I would have assumed that
Code:
transform some_button():
    function test_fn()
should have been

Code:
transform some_button():
    function test_fn
I may be wrong, but it seems like you're calling the function at the time it's declared (well before anything is hovered or not) rather than passing a callable to be called in real time. (Look at the example at ) Maybe that's why you're not seeing what you expect?

Looking at the code, the default_function that's the part of the class that updates things, it looks like arguments is used to store what should happen based on the current state, but that the state is retrieved from self.style.

Mind you, this is with about 5 minutes worth of looking at the code and no experimentation whatsoever...
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Ok, I regularly come to read again your post, and I still absolutely don't get what you are trying to ask.

So currently I'm passing a transform function to change some states of buttons,
What do you mean by "change states of buttons" ? Buttons have really few states (idle, hovered, clicked, selected and sensitive) and only the last twos can possibly depend on you ; yet through theselected and sensitive property.
You can also kind of trigger the hovered state since you can move the mouse through the code, but anyway none of those states exist to be played with. You don't change the "sensitive" state for fun, you change it because right now the player must, or must not, be able to click on the button.


I know I can calculate it manually, but I'm wondering if there is some out-of-the-box solution and how can I get current state of the element (eg. hovered or selected)?
What's wrong with the on idle and on hover in the first code you shown ? They are the "out-of-the-box solution" to get the current state of the element.


Source code says there's a arguments field in Transform class, that should have those states, but for me it's constantly empty.
There's an arguments field, but why should it store the states of the button ? Accordingly to its name, it store arguments past to the transform object when it was created, nothing more.
What you are searching for is transform_event, that will contain a string representing the state, or None when there's no state because the button is not part of the foreground screen(s).
I haven't tested, but I don't believe that changing the value of transform_event would have an effect.
 

Sagisu

Newbie
Nov 12, 2017
30
25
I'm not 100% sure, but looking at your code, I would have assumed that (...) should have been (...)
Yea, sorry. I was writing out of my head to illustrate what I'm trying to achieve. You're right - in my code I'm passing a function reference and not calling it.

Looking at the code, the default_function that's the part of the class that updates things, it looks like arguments is used to store what should happen based on the current state, but that the state is retrieved from self.style.
Oh.. so those are not accessable for me. That's a pity =/


What do you mean by "change states of buttons" ? Buttons have really few states (idle, hovered, clicked, selected and sensitive) and only the last twos can possibly depend on you ; yet through theselected and sensitive property.
I'll try to elaborate more on that problem. I know that button has those states and I can manage them indirectly via ATL block, but I'd like to have more control over it.
What I mean is: I'm currently having a button that has hover effect using ATL:
Code:
transform button_transform(is_selected):
    xpos 300
    on idle:
        easein 0.7 xpos 0
    on hover:
        easein 0.3 xpos -60

screen some_button(label, is_selected):
    button at button_transform(is_selected):
        text label
        action NullAction
That's working well for static (not moving) button, but I need to change behaviour of transform states (I dunno how to call them) like hover or idle depending on what is the status of button (well - more precise: what is the variable passed to the screen)

I've found a workaround for it:
Code:
transform button_transform(is_selected):
    xpos 300
    on idle:
        easein 0.7 xpos 0 # can't use condition statements here
    on hover:
        easein 0.3 xpos -60

transform button_transform_selected():
    xpos 300
    on idle:
        easein 0.7 xpos -60
    on hover:
        easein 0.3 xpos -70

screen some_button(label, is_selected):
    button
        if is_selected:
            at button_transform_selected
        else:
            at button_transform
        text label
        action NullAction
...yet still I have to use two ATL blocks for it and before I found that solution I was trying to do that with ATL function (because passing variable to ATL block and changing that variable won't rerender screen and I'll stuck with the problem I once had).
So, to do that I've created function, used it in ATL block and for all static data it worked fine - I change variable, button changes it's position and other attributes. But I had a problem with animating it - couldn't find a way to use all that on idle/hover substitute for function.

Long story short - I've already found a workaround solution that isn't that problematic for me, but I'm still kinda curious if there's a way to animate things using transform function (or - is there a way to do it out of the box, because I can do it 'manually' calculating time deltas etc.)