britzl / defold-input

Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
MIT License
112 stars 26 forks source link

Cursor.listen not working with url strings #35

Closed pabaucom closed 10 months ago

pabaucom commented 10 months ago

Found when using the example code in cursor.md, it does not work as expected. The callback is never called.

From the current cursor.md:

-- not work
cursor.listen("#cursor", cursor.DRAG_START, function(message_id, message)
    -- prevent dragging of blue aliens
    if message.group == hash("blue") then
        return true -- return true to block the event
    end
end)

It does work as expected if we use the full url instead of the url string "#cursor":

-- works
cursor.listen(msg.url("#cursor"), cursor.DRAG_START, function(message_id, message)
    -- prevent dragging of blue aliens
    if message.group == hash("blue") then
        return true -- return true to block the event
    end
end)

The URL is also how it is in the example controller.script

I was going to submit a PR for cursor.md with updated example code, but then I saw that it says cursor.listen() should take either a url or string, so I'm not sure if the doc needs fixed or cursor.lua needs fixed.