Joystick and Director

Hello Corona Community!

I am using the Joystick class from http://developer.anscamobile.com/code/joystick. I am trying to use the Joystick with the Director 1.4, however I’m receiving an attempt to index global ‘joystick’ (a nil value) error. Can someone help me with what I’m doing wrong?

Error


\Code\tileEngine.lua:61: in function \Code with Runtime error
\Code\tileEngine.lua:61: attemt to index global ‘joystick’ (a nil value) stack traceback:

Code

  
module(..., package.seeall)  
  
new = function ()  
  
 ------------------  
 -- Groups  
 ------------------  
  
 local localGroup = display.newGroup()  
  
 -- Setup Environment  
 display.setStatusBar( display.HiddenStatusBar )  
 system.activate( "multitouch" )  
 local movieclip = require("movieclip")  
  
 -- Load Tile Engine  
 local tileEngine = require( "tileEngine" )  
  
 -- Generate Background  
 local background = tileEngine.newSurface( "background.png" , 2 , 2 , 1 , 1 , 0 )  
 localGroup:insert(background)  
  
 -- Generate Clouds  
 local clouds1 = tileEngine.newSurface( "clouds1.png" , 2 , 3 , 1 , 1 , 0 )  
 localGroup:insert(clouds1)  
  
 -- Load Plane  
 local plane = require( "plane" )  
 localGroup:insert(plane)  
  
 -- Generate More Clouds  
 local clouds2 = tileEngine.newSurface( "clouds2.png" , 2 , 5 , 1 , 0.8 , 0 )  
 localGroup:insert(clouds2)  
  
 -- Load Joystick Class  
 local joystickClass = require( "joystick" )  
  
 -- Add A New Joystick  
 joystick = joystickClass.newJoystick{  
 outerImage = "", -- Outer Image - Circular - Leave Empty For Default Vector  
 outerRadius = 60, -- Outer Radius - Size Of Outer Joystick Element - The Limit  
 outerAlpha = 0, -- Outer Alpha ( 0 - 1 )  
 innerImage = "joystickInner.png", -- Inner Image - Circular - Leave Empty For Default Vector  
 innerRadius = "", -- Inner Radius - Size Of Touchable Joystick Element  
 innerAlpha = 1, -- Inner Alpha ( 0 - 1 )  
 backgroundImage = "joystickDial.png", -- Background Image  
 background\_x = 0, -- Background X Offset  
 background\_y = 0, -- Background Y Offset  
 backgroundAlpha = 1, -- Background Alpha ( 0 - 1 )  
 position\_x = 25, -- X Position Top - From Left Of Screen - Positions Outer Image  
 position\_y = 335, -- Y Position - From Left Of Screen - Positions Outer Image  
 ghost = 155, -- Set Alpha Of Touch Ghost ( 0 - 255 )  
 joystickAlpha = 0.4, -- Joystick Alpha - ( 0 - 1 ) - Sets Alpha Of Entire Joystick Group  
 joystickFade = true, -- Fade Effect ( true / false )  
 joystickFadeDelay = 2000, -- Fade Effect Delay ( In MilliSeconds )  
 onMove = plane.planeControl -- Move Event  
 }  
 localGroup:insert(joystick)  
 ------------------  
 -- MUST return a display.newGroup()  
 ------------------  
  
 return localGroup  
  
end  
  

[import]uid: 14218 topic_id: 15402 reply_id: 315402[/import]

I was going to say you didn’t require the module, I wrote a long post then realized you did it was at the bottom.

So yea, I can’t delete this post so here we are.
Have you tried creating a local for the joystick and getting things to work before placing everything into one large function?

Usually (because im too new to know what I am doing yet) I set everything up line by line until something breaks. Once everything works, then I start doing these large functions and putting everything into there.
I had the same problem with this, and I ended up using another joystick class that was much easier for me to deal with.

http://developer.anscamobile.com/code/simple-analog-stick-joystick-module

I really liked that joystick better than what you are using, but that is a personal preference :slight_smile:

For your situation, are you using a daily build or is this 591 (the stable version)?

ng

[import]uid: 61600 topic_id: 15402 reply_id: 56979[/import]

Require joystick outside the code, I would do it somewhere near the top of main.

Joystick was not designed for Director as it came before it so I can’t say for sure but if you have the module outside the new function it will persist across screens. [import]uid: 5354 topic_id: 15402 reply_id: 57618[/import]