Action to move image and change variable on a Screen

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
lindsay-jb
Regular
Posts: 61
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Action to move image and change variable on a Screen

#1 Post by lindsay-jb » Wed Sep 28, 2022 12:14 pm

I'm working on a game with a dress-up screen. On this screen, I have an image of the main character and two buttons. I want to make the MC image move left/right offscreen, change into a new outfit, and move out from the other side of the screen when you press the buttons.

Code: Select all

screen outfit_game():
    default move = truecenter

    add "mc big" at move

    imagebutton:
            idle "arrow left.png"
            action (
                    SetScreenVariable("move", toOffscreenLeft),
                    Function(PreviousOutfit),
                    SetScreenVariable("move", fromOffscreenRight),
                    SetScreenVariable("move", truecenter)
            )

    imagebutton:
            idle "arrow right.png"
            action (
                    SetScreenVariable("move", toOffscreenRight),
                    Function(NextOutfit),
                    SetScreenVariable("move", fromOffscreenLeft),
                    SetScreenVariable("move", truecenter)
            )
My current code looks like this. The problem is that all the actions are fired off in a way that the next action doesn't wait for the completion of the previous, so it appears as if the transforms aren't applied at all (because they're quickly overwritten).
How do I solve this problem? Is there a way to insert a variable change into an ATL transform or to add a callback to an ATL transform without breaking it, or maybe a way to make an action wait for the completion of the previous action? Or is there a better solution?

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Action to move image and change variable on a Screen

#2 Post by enaielei » Wed Sep 28, 2022 12:32 pm

Screen timers would probably help.
Additionally, containing the transforms inside one transform might work.

Code: Select all

init python:
    def tfn(tr, st, at, callback=None):
        fn = callback
        if callable(fn):
            fn()
            renpy.restart_interaction()

transform move_left(fn=None):
    toOffscreenLeft
    pause 1.0 # how long do we need to wait before doing the next transform?
    function renpy.partial(tfn, callback=fn)
    fromOffscreenRight
    pause 1.0
    truecenter
    
transform move_right(fn=None):
    toOffscreenRight
    pause 1.0
    function renpy.partial(tfn, callback=fn)
    fromOffscreenLeft
    pause 1.0
    truecenter
Then in your code.

Code: Select all

imagebutton:
    idle "arrow left.png"
    action SetScreenVariable("move", move_left(PreviousOutfit))
Note: Untested

lindsay-jb
Regular
Posts: 61
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Action to move image and change variable on a Screen

#3 Post by lindsay-jb » Wed Sep 28, 2022 11:55 pm

That worked perfectly, thank you so much!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]