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: 44
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 » Tue Oct 09, 2018 3:44 pm

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
Miko-Class Veteran
Posts: 964
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I cannot draw very well)
Projects: An un-named 3d 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 » Tue Oct 09, 2018 8:01 pm

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
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Finish Catmull-Rom Spline pathing
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

philat
Eileen-Class Veteran
Posts: 1447
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 » Wed Oct 10, 2018 12:49 am

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