joystick - attempt to call global 'post' error

  1. You don’t need SSK and SSK Core.  Just include SSK.  If you use both, the one you use second may override the prior.

ssk_core is a lightweight version of ssk I used in a few examples and Corona Geek projects.

  1. Did you add this line line in main.lua near the top?

    require “ssk.loadSSK”

Having the ssk folder (and subfolders) isn’t enough.  You have to load SSK to initialize it.

As you suggested I now just have only the ssk folder in my project, and I added “local joystick = require(‘ssk.loadSSK’)” near the top of my main.lua and to my level1.lua file.  Further down in my level1.lua I have the joystick.create command (referenced in my original post above) which is now producing the runtime error “…:106: attempt to call field ‘create’ (a nil value)”.

@roaminggamer  - I added just “require “ssk.loadSSK”” to my main.lua near the top and in my level1.lua file I added “local joystick = require “ssk.RGEasyInputs.joystick”” to the top.  I’m getting to the joystickListener function, but I’m getting a runtime error "bad argument #1 to ‘ipairs’ (table expected, got nil), when I execute the line “for k,v in ipairs( labelNames ) do”.  It appears nothing is assigned to ipairs.  What’s wrong?

The event table is not numerically indexed (ipairs() is numeric).

Use pairs().

joystickListener = function( event ) for k,v in pairs( event ) do print(k,v) end end

It’s now getting to the joystickListener function, but the onscreen joystick doesn’t seem to be moving in the simulator.  I running Corona on Windows PC and viewing as a NexusOne in the simulator if that helps.  Shouldn’t the image of the joystick move onscreen as you move it?

The code below prints:

phase moved

49

32

49

0

moved

off

124

nil

joystickListener = function( event ) for k,v in pairs( event ) do print( k,v) print( event.vx ) print( event.vy ) print( event.nx ) print( event.percent ) print( event.phase ) print( event.state ) print( event.angle ) print( event.direction ) end end Runtime:addEventListener("myJoystickEvent", joystickListener)

I’m pretty busy right now.  

Tell you what.  Later today I’ll take a break and make a micro example:

  • using latest ssk
  • with joystick on screen
  • moving dot as result of touching joystick.

Then, if there are any issues with joystick code I’ll see and fix them.  If not, you’ll see how it works.

First I need to do client and EAT work.  So, check back tonight.

-Ed

Thank you Ed, I appreciate all of your help!  The biggest issue appears to be with the event.state always having a value of “off”, and the direction appears to always be set to “nil”.

Link to full example:
http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/04/joystick.zip

Video of example:

https://www.youtube.com/watch?v=TM3Z_8w1cd0&feature=youtu.be
 
Pertinent code:

io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) require "ssk.loadSSK" -- 1. Always use groups to contain objects local group = display.newGroup() -- 2. Let's make a background -- centerX, centerY, fullw, fullh - All globals from SSK local back = display.newRect( group, centerX, centerY, fullw, fullh ) back:setFillColor( unpack(\_CYAN\_) ) -- \_CYAN\_ from SSK back.alpha = 0.10 -- 3. It is NOT suggested that you use the joystick code directly. -- Use the oneStick easy input instead. That is why I wrote the easy input helpers. :) -- Yes, I know this stuff is not well documented. -- ssk.easyInputs.oneStick.create( group, { -- Parameters to oneStick builder: eventName = "myJoystickEvent", -- defaults to onJoystick -- Parameters to joystick builder: joyParams = { doNorm = true, -- Calculate normalized vectors and send in event -- This is expensive by default it is false } } ) -- 4. Now make an object to listen for joystick events and to do something -- when it gets them. local bob = display.newImageRect( group, "smiley.png", 48, 48 ) bob.x = centerX bob.y = centerY bob.mx = 0 bob.my = 0 bob.rate = 250 -- pixels-per-second bob.lastTime = system.getTimer() function bob.myJoystickEvent( self, event ) if( autoIgnore( "myJoystickEvent", self) ) then return end -- Table dumper from SSK (for debug) table.dump(event) self.mx = -event.nx self.my = -event.ny self.rotation = event.angle end; listen( "myJoystickEvent", bob ) -- Not a great way to move, but hey its a quick example... -- function bob.enterFrame( self ) if( autoIgnore( "enterFrame", self) ) then return end local curTime = system.getTimer() dt = self.lastTime - curTime self.lastTime = curTime self.x = self.x + self.mx \* self.rate \* dt/1000 self.y = self.y + self.my \* self.rate \* dt/1000 end; listen( "enterFrame", bob )

@roaminggamer - That’s awesome.  Thanks very much for following-up, and I really enjoy your work.  Keep it up!!