Hello,
I’m using Defold Input to create a card game, with simple drag and drop, but I can’t have the listener to work, to prevent dragging some objects.
This :
cursor.listen(msg.url("#cursor"), cursor.DRAG_START, function(message_id, message)
if message.group == msg_card then
return true -- return true to block the event
end
end)
returns an error : “You must provide a valid cursor script url”.
I tried to set it up exactly like the drag and drop example, and call listen() in the init() function, but it doesn’t work.
I have a “game” object, with the cursor script (#cursor) attached, and a main controller script (#game).
All other events and messages work fine. Only the listener doesn’t.
Does anyone have an idea ?
Thanks a lot !
Note that msg.url("#cursor") must resolve to the URL of the cursor.script. In your snippet of code it is assumed that the the script you are calling cursor.listen() from is attached to the same game object as the cursor.script.
The order in which game object component init() functions are called is unspecified. You should not assume that the engine initializes objects belonging to the same collection in a certain order.
A really hacky solution that might work is to send a message to itself on init and then run your code upon receiving that message.
Hello !
Thanks for your tip !
That was the issue ! I replaced the snippet with a msg.post(".", “listen”), and handle the listen() call in the message handler, and it worked.
So, @britzl , you’ve been lucky the examples in Defold-input work, right ?
First I assumed the scripts were loaded in the same order as in the hierarchy, but that’s not the case. Renaming the controller script “a.script” didn’t make a difference.
Anyway, it works now !
Thanks both for your help !