[SOLVED]'on replace:' ATL statement not working

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
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

[SOLVED]'on replace:' ATL statement not working

#1 Post by RicharDann »

I have a couple images that are supposed to replace each other when a button is hovered or not.

I wanted to set it up so when the image appears for the first time, and when it's hidden, it does with a dissolve-like animation,
and when it's replaced with another image, it does with a sort of horizontal flip. This image represents a character going from
one stance to another, hence the need of using different animations for entering, exiting, and changing state.

So I declared the images like this, using ATL statements:

Code: Select all

image Hero_AttackPose:
    "images/battler/Hero_attack.png"

    on show:
        alpha 0
        linear .2 alpha 1.0

    on replace:
        linear .1 xzoom 0
        linear .1 xzoom 1

image Hero_StandbyPose:
    "images/battler/Hero_stand.png"

    on show:
        alpha 0
        linear .2 alpha 1.0

    on replace:
        linear .1 xzoom 0
        linear .1 xzoom 1

#This variable is used to change what image will be displayed
default Hero_BattlePose = 'Hero_StandbyPose' 

And added it to a screen:

Code: Select all

screen HR_Test():

    #This displays the image
    add Hero_BattlePose:
        xalign .5

    #The button to test wether the image changes on hover or not
    textbutton "Attack":
        xpos .2
        ypos .7
        hovered SetVariable('Hero_BattlePose', 'Hero_AttackPose')
        unhovered SetVariable('Hero_BattlePose', 'Hero_StandbyPose')
        action NullAction
When I run this code and place the mouse over the button, the images are changed with a nice dissolve effect,
but the 'replace' statement in them is never executed. If I place the xzooms inside the show block, they play correctly,
looks like only the show statement is executed as if each image it's showing for the first time, it doesn't seem to recognize the image is being replaced by another.

I thought of triggering the replace event myself somehow, or create a 'changeToAttackPose' event, but while the documentation states that you can generate your own events (I think?) it doesn't provide an example on how to do so, so I don't want to mess with it
until I know exactly what I'm doing.

So am I doing something incorrectly that does not trigger the 'replace' flag, or is my understanding or my entire approach on this problem wrong? Is there an example or a detailed explanation out there on how do this events work?

I've been stuck on this for days, any small help would be greatly appreciated.
Last edited by RicharDann on Mon Sep 18, 2017 9:55 am, edited 1 time in total.
The most important step is always the next one.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: 'on replace:' ATL statement not working

#2 Post by xela »

replace
Triggered when transform is shown using the show statement, replacing an image with the given tag.
This is not what you're doing... you may want to look into showing the sprites on screens of their own and just feed them unique sets of ATL instructions. Bypassing atl external atl events handling completely. There are many setups that will get the job done, not knowing anything about the complexity you may require in the future, it's really difficult to give coherent advice.

Normally, when people don't need something terribly complicated with dozens of different events that require very precise timing, just using a simple while loop OR a screen for main GUI and separate screens to show sprites (or conditioned stuff that you need to update on interactions) is a good way to go.
Like what we're doing? Support us at:
Image

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: 'on replace:' ATL statement not working

#3 Post by RicharDann »

Thank you xela! I see now, indeed this works only with show statement, I feel so silly now for not reading the Documentation properly. In that case, your suggestion of making a screen for each sprite and then using them all togheter does seem promising.

I'm sure I'll figure out a workaround for this, thanks again for your helpful advice.
The most important step is always the next one.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: 'on replace:' ATL statement not working

#4 Post by Imperf3kt »

Isn't it "on replaced" not "on replace"
https://www.renpy.org/doc/html/atl.html#external-events
replaced
Triggered when the transform is replaced by another. The image will not actually hide until the ATL block finishes
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: 'on replace:' ATL statement not working

#5 Post by RicharDann »

Imperf3kt wrote: Sun Sep 17, 2017 8:40 am Isn't it "on replaced" not "on replace"
https://www.renpy.org/doc/html/atl.html#external-events
replaced
Triggered when the transform is replaced by another. The image will not actually hide until the ATL block finishes
Thanks, but I also tried that later, it didn't work either.

Anyway I rewrote the entire system using different screens and separate transforms and it works like a charm now.

It ended up looking like this:

Code: Select all

transform hero_battle_entrance(x):
    xalign x
    zoom 2.0
    linear .2 zoom 1.0

    on hide:
        parallel:
            linear .2 alpha 0
            linear .2 zoom 4.0

transform hflip(x):

    xalign x
    xzoom 0
    linear .1 xzoom 1

    on hide:
        parallel:
            linear .2 zoom 2.0
            linear .2 alpha 0

define hero_attack_stance = "images/battler/Hero_attack.png"
define hero_stand_stance = "images/battler/Hero_stand.png"
define hero_magic_stance = "images/battler/Hero_magic.png"

default hero_stance = None

screen ShowHeroStance():

    on "hide":
        action SetVariable('hero_stance', None)

    if hero_stance == None:
        add hero_stand_stance at hero_battle_entrance(.5)
    if hero_stance == 'standby':
        add hero_stand_stance at hflip(.5)
    if hero_stance == 'attack':
        add hero_attack_stance at hflip(.5)
    if hero_stance == 'magic':
        add hero_magic_stance at hflip(.5)

screen AttackButton(x, y):
    frame:
        xalign x
        yalign y
        textbutton "Attack":
            hover_sound "audio/se/Sword4.ogg"
            hovered [
                     Hide('ShowHeroStance'),
                     SetVariable('hero_stance', 'attack'),
                     Show('ShowHeroStance', None),
                    ]
            unhovered [
                       Hide('ShowHeroStance'),
                       SetVariable('hero_stance', 'standby'),
                       Show('ShowHeroStance', None),
                      ]
            action NullAction


screen HR_BattleScreen():

    on "show":
        action Show('ShowHeroStance', None)

    on "hide":
        action Hide('ShowHeroStance')

    use AttackButton(.2, .6)
Thank you both of you for your help!
The most important step is always the next one.

Post Reply

Who is online

Users browsing this forum: No registered users