Page 1 of 1

Why does clicked event fire on drag-drop in console and when starting the game?

Posted: Tue Oct 09, 2018 3:44 pm
by newbiemate
I am trying to pass some data to the clicked event when I click on a drag item, but the event seems to fire constantly when I'm in console mode and when the game starts.

Here is the snippet I am playing around with:

Code: Select all

init python:

    def unit_clicked(name):
        print "clicked on ", name

    def detective_dragged(drags, drop):

        if not drop:
            return

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

        return True

screen send_detective_screen:


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

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "one.png"
            droppable False
            dragged detective_dragged
            clicked unit_clicked("Ivy")
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "one.png"
            droppable False
            dragged detective_dragged
            clicked unit_clicked("Zack")
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "two.png"
            draggable False
            xpos 450 ypos 140
        drag:
            drag_name "Paris"
            draggable False
            child "two.png"
            xpos 500 ypos 280

label start:
    "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]."
When I start the game, immediately in console I see:

Code: Select all

clicked on Ivy
clicked on Zach
And if I press enter in the console, it prints the same thing.

If I'm not using the clicked event properly, what's a good way to call a function with parameters after the drag item has been clicked?

Re: Why does clicked event fire on drag-drop in console and when starting the game?

Posted: Tue Oct 09, 2018 8:01 pm
by Remix
You cannot pass an arbitrary parameter to any drag event, though you can use the activated attribute

Code: Select all

init python:
    def my_drag_activated_function(drags):
        print( " and ".join( [ drag.name for drag in drags ] ) )

# some screen
    drag:
        activated my_drag_activated_function
That function (or list of functions) will be passed one argument, a list of drags that are being dragged

note: activated is a recent addition to Ren'Py, so use an up to date version

Re: Why does clicked event fire on drag-drop in console and when starting the game?

Posted: Wed Oct 10, 2018 12:49 am
by philat
You can also curry the function so that it works with clicked -- technically, I think clicked fires on mouse-up, as opposed to mouse-down for activated.