EDIT:
My issue was caused in my key bindings file that both “key_trigger” and “touch_trigger” had the same name string “jump”. The fix was just to rename the triggers under key_trigger and touch_trigger didn’t names.
ORIGINAL POST:
Hi.
I downloaded Defold today and am currently following the “Getting Started”/“platformer” tutorial.
I’m on the second page of the tutorial which after setting up the hero and adding collision to the ground collection, it said if I built and ran the game, I’d be able to jump the hero, but I’m currently getting no input.
I tried adding a print string when any input is pressed in the “onInput” function for the hero script, but nothing is being logged in the console.
I do have the keybinding set to jump when KEY_SPACE is pressed.
Everything up to this point in the tutorial seems to be fine. Level collection has my ground, my hero, the ground is scrolling, the hero is colliding with the ground and running on start up… But no keys are being detected in the hero script.
Did I miss something?
Hmm, very odd. Try a minimal example with a collection containing a single game object with a script attached and set this as your main collection. In the script put only this:
function init(self)
msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
print(action_id)
end
Also make sure that your game.project file actually points to the correct input binding file. Do you get any prints at all?
It’s strange that it works in the HTML build but not on Mac. Still, it’s good if you could isolate it down to a single collection, game object and script.
New project.
Empty level.
Created a game object with the script given by @britzl.
I added a print message in the init just to make sure it’s running.
So…
function init(self)
msg.post(".", “acquire_input_focus”)
print(‘Hello from this script.’)
end
function on_input(self, action_id, action)
print(action_id)
end
Here is my debug:
INFO:ENGINE: Defold Engine 1.2.73 (181bfb1)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: Hello from this script.
Pressing keys does nothing.
EDIT:
Sorry - and my bindings are linked correctly from what I can tell. /input/game.input_bindingc
Fixed it.
This is something I didn’t realise.
My touch_trigger and my key_trigger were both name “jump” and clashed.
I didn’t think this was necessary to rename the bindings and thought naming them the same with keep the code consistent (jump is the action across input keys/types).
I guess on Mac is clashed and that is why the HTML target didn’t clash with a touch input (through Chrome on Mac) and it’s why I didn’t get the error there.
I don’t know if you want to delete this thread, or keep it here for others to find (I’ll add it to my original post that touch_triggers and key_triggers cannot be the same if targeting the Mac platform).
My question now is:
Is this something that must be done? key_trigger and touch_trigger must have different action names even though it’s doing the same action under different platforms?
Could it be because the Mac trackpad can take multitouch events? (You can pan, pinch to zoom and more).
If what @britzl said is correct, the Mac target may have conflicting trigger handling in specifically a multi-touch input methods.