Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
adding Keyboad event listeners to a game — Gideros Forum

adding Keyboad event listeners to a game

Unknown Member
edited March 2014 in Code snippets
I'm trying to get into gideros development to create a game...

I've downloaded a tutorial from http :// bluebilby.com/2013/05/08/gideros-mobile-tutorial-creating-your-first-game/#codesyntax_13, and I am trying to alter it so that I can move the 'player' from the keyboard

So I have added the following functions to main.lua:

function onKeyDown(event)
print("key down:"..event.keycode)
end

function onKeyUp(event)

end

and below the line stage:addEventListener(Event.ENTER_FRAME, updateAll), I have added the following two lines:
stage:addEventListener(Event.KEY_DOWN, onKeyDown, event)
stage:addEventListener(Event.KEY_UP, onKeyUp, event)

but whenever I press a key on the keyboard after running the game I get the following message:

main.lua:326: attempt to concatenate field 'keycode' (a nil value)
stack traceback:
main.lua:326: in function

Comments

  • it should be event.keyCode
  • ar2rsawseenar2rsawseen Maintainer
    And you should not pass event data to key event listeners, it could be simply:
    stage:addEventListener(Event.KEY_DOWN, onKeyDown)
    stage:addEventListener(Event.KEY_UP, onKeyUp)
    ;)
Sign In or Register to comment.