[Solved] Remove old dragged when new dragged is placed into the same droppable

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
omranpanda
Newbie
Posts: 15
Joined: Tue Nov 03, 2020 4:29 pm
Contact:

[Solved] Remove old dragged when new dragged is placed into the same droppable

#1 Post by omranpanda » Wed Aug 11, 2021 10:03 am

Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop.

I'm using a slightly modified code of the one found here https://www.renpy.org/doc/html/drag_drop.html

Here is the code:

Code: Select all

init python:

    def detective_dragged(drags, drop):

        if not drop:
            return

        store.detective = drags[0].drag_name
        store.city = drop.drag_name

        return

screen send_detective_screen:

    # A map as background.
    add "europe.jpg"

    # A drag group ensures that the detectives and the cities can be
    # dragged to each other.
    draggroup:

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "ivy.png"
            droppable False
            dragged detective_dragged
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "zack.png"
            droppable False
            dragged detective_dragged
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "london.png"
            draggable False
            xpos 450 ypos 140
            
            
    key "b" action Return()


label send_detective:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_detective_screen

    "Okay, we'll send [detective] to [city]."
Last edited by omranpanda on Fri Sep 03, 2021 3:48 pm, edited 1 time in total.

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

Re: Remove old dragged when new dragged is placed into the same droppable

#2 Post by Alex » Wed Aug 11, 2021 2:15 pm

omranpanda wrote:
Wed Aug 11, 2021 10:03 am
Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop....
Try it like - viewtopic.php?f=8&t=38835&p=417941&hilit=snap#p417941

omranpanda
Newbie
Posts: 15
Joined: Tue Nov 03, 2020 4:29 pm
Contact:

Re: Remove old dragged when new dragged is placed into the same droppable

#3 Post by omranpanda » Thu Aug 12, 2021 8:41 am

Alex wrote:
Wed Aug 11, 2021 2:15 pm
omranpanda wrote:
Wed Aug 11, 2021 10:03 am
Hello, I want to know how would I go about making it so that when a new drag is placed into an already occupied drop it would displace the old drag outside of the drop....
Try it like - viewtopic.php?f=8&t=38835&p=417941&hilit=snap#p417941
Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?

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

Re: Remove old dragged when new dragged is placed into the same droppable

#4 Post by Alex » Thu Aug 12, 2021 1:07 pm

omranpanda wrote:
Thu Aug 12, 2021 8:41 am
...Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?
Khm, the whole thing. You need to store positions for each draggable to know where to put old drag when new one is placed over occupied slot. Then you need to code the action in detective_dragged function (in my sample it's a my_dragged function). So, it became a bit complicated. In sample code I put some comments.

omranpanda
Newbie
Posts: 15
Joined: Tue Nov 03, 2020 4:29 pm
Contact:

Re: Remove old dragged when new dragged is placed into the same droppable

#5 Post by omranpanda » Fri Sep 03, 2021 3:47 pm

Alex wrote:
Thu Aug 12, 2021 1:07 pm
omranpanda wrote:
Thu Aug 12, 2021 8:41 am
...Sorry but could you specify which part I should be looking at and explain it with a bit more detail if you may?
Khm, the whole thing. You need to store positions for each draggable to know where to put old drag when new one is placed over occupied slot. Then you need to code the action in detective_dragged function (in my sample it's a my_dragged function). So, it became a bit complicated. In sample code I put some comments.
Ah, alright thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]