So I have been using the following code to control a rock on the screen and it works great without errors but when I switch screens (I’m using the director class) I get a repetitive error and parts of the level stops working
This is the code…
-- This is line 47 and below is 48 and so on...
local function onAccelerate( event )
system.setAccelerometerInterval(50)
motionx = 30 \* event.xGravity
end
Runtime:addEventListener ("accelerometer", onAccelerate)
local function moverock (event)
rock.x = rock.x + motionx
end
Runtime:addEventListener("enterFrame", moverock)
local function wrapit (event)
if rock.x \< -36 then
rock.x = 356
elseif rock.x \> 356 then
rock.x = -36
end
end
Runtime:addEventListener("enterFrame", wrapit)
--...this is line 68 and above is 67. Just thought it would help figure out the error
and this is the error…
Runtime error
…nykilkenny/Desktop/Today’s Tutorials/acc_ball/L1.lua:55: attempt to perform arithmetic on field ‘x’ (a nil value)
stack traceback:
[C]: ?
…nykilkenny/Desktop/Today’s Tutorials/acc_ball/L1.lua:55: in function <…nykilkenny tutorials>
?: in function <?:215>
This keeps going on forever. Please help me stop it 
Thank you,
Danny
[import]uid: 59140 topic_id: 16772 reply_id: 316772[/import] </…nykilkenny>
