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

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
newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

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

#1 Post 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?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

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

#2 Post 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
Frameworks & Scriptlets:

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

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

#3 Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users