Page 1 of 1

(solved)How do I script a reposition of drag within a screen?

Posted: Thu Feb 14, 2019 4:12 pm
by SONTSE
Let's say I have a screen with a draggable object inside

Code: Select all

screen say(who, what):
    style_prefix "say"
    drag:
        drag_name 'screen_say'
        window:
            id "window"
    
            if who is not None:
    
                window:
                    id "namebox"
                    style "namebox"
                    text who id "who"
    
            text what id "what"
and I want it to move into a certain position, ideally with ease effect something like

Code: Select all

    e 'and now i move your draggable say screen!'
    show screen_say:
        ease .5 pos (0,400)
    pause 1
    e 'see? it's moving. It's alive!'
unfortunately it seems transforms cannot be applied directly on screens, and I have no idea of how to approach the drag within a screen. So I would be thankful for any suggestions!

Re: How do I script a reposition of drag within a screen?

Posted: Thu Feb 14, 2019 9:32 pm
by Remix
Maybe (untested)

$ renpy.get_widget( "say", "screen_say" ).snap( 0, 400, 0.5 )

Re: How do I script a reposition of drag within a screen?

Posted: Fri Feb 15, 2019 11:32 am
by SONTSE
Remix wrote:
Thu Feb 14, 2019 9:32 pm
Maybe (untested)

$ renpy.get_widget( "say", "screen_say" ).snap( 0, 400, 0.5 )
Thanks! That surely did lead to a working solution.
Although it won't work like this because no say screen is shown when $ scripts are executed,
hence get_widget returns None instead of a widget.
So there is some tricky way to actually get this done.

Code: Select all

init python:
    def drag_move(drag):
        try:
            drag.snap(0,400,delay=.5)
        except:
            pass

screen move_drag:
    default say_drag = renpy.get_widget('say','drag')
    timer 1 action Function(drag_move,say_drag)

screen say(who, what):
    on 'show' action Show('move_drag')    
    drag:
        style_prefix "say"
        drag_name "screen_say"
        id "drag"
        yalign 1.0
        window:
            id "window"       
            if who is not None:
                window:
                    id "namebox"
                    style "namebox"
                    text who id "who"
            text what id "what"

label main_menu:
    return

label start:
    'Look! It\'s moving!'
    'It\'s alive!'
    return