[SOLVED] How to get xpos and ypos of drag?

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
Yjga125
Newbie
Posts: 6
Joined: Sat Mar 18, 2017 8:47 pm
Contact:

[SOLVED] How to get xpos and ypos of drag?

#1 Post by Yjga125 »

How to get xpos and ypos of drag?
I'm trying to get xpos and ypos of drag by using this script:

Code: Select all

init python:
    def Mouse(x):
        x=renpy.get_mouse_pos()
        return x
init:
    default Curr_xpos= Tooltip ('Hey')
    default Curr_ypos= Tooltip ('')
    $ Curr_x=[]
screen Curr_map_screen:
    drag:
        drag_name "say"
        xpos 600
        ypos 600
        child "images/Travel_icon.png"
        dragged Mouse(Curr_x)
screen Mouse_display:
    vbox:
        xpos 100
        ypos 100
        label "[Curr_x]"
label start:
    show screen Mouse_display
    show screen Curr_map_screen
    $ r1=Mouse(Curr_x)
    "[r1]"
    jump start
But I've got an exception:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 25, in script
"[r1]"
TypeError: 'int' object is not callable
What am I doing wrong?
Last edited by Yjga125 on Mon Feb 19, 2018 3:12 pm, edited 1 time in total.

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: How to get xpos and ypos of drag?

#2 Post by irredeemable »

I've never dabbled in drag and drop but just quickly checking the documentation this code seems to have a lot wrong with it. Did you get it from somewhere or are you trying to work it out for yourself?

Yjga125
Newbie
Posts: 6
Joined: Sat Mar 18, 2017 8:47 pm
Contact:

Re: How to get xpos and ypos of drag?

#3 Post by Yjga125 »

Yes, I tried to work it by myself.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to get xpos and ypos of drag?

#4 Post by Alex »

Try something like

Code: Select all

default test_x = 100
default test_y = 100

image my_img:
    Solid("#c00")
    size(150,150)


init python:
    def drag_func(drags, drop):
        if not drop:
            store.test_x = drags[0].x
            store.test_y = drags[0].y
            renpy.restart_interaction() # to refresh values onscreen imediately
            
            return
        
screen drag_test_scr():
    text "[test_x] / [test_y]" align(0.5, 0.05)
    
    draggroup:
        drag:
            drag_name "test_drag"
            child "my_img"
            droppable False
            dragged drag_func
            pos (test_x, test_y)


# The game starts here.
label start:
    "..."
    $ renpy.retain_after_load() # to save changes made before game reached Line 2
    show screen drag_test_scr

    "Line 1."

    "Line 2"

    return
https://www.renpy.org/doc/html/drag_drop.html#examples
https://www.renpy.org/doc/html/save_loa ... after-load
https://www.renpy.org/doc/html/other.ht ... nteraction

Yjga125
Newbie
Posts: 6
Joined: Sat Mar 18, 2017 8:47 pm
Contact:

Re: How to get xpos and ypos of drag?

#5 Post by Yjga125 »

Thanks a lot!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]