I’m getting the “attempt to index global “box” (a nil value) stack traceback” in line 41 and here’s the code:
boxSpawned= 0 local \_T = display.screenOriginY local \_B = display.viewableContentHeight - display.screenOriginY local \_L = display.screenOriginX local \_R = display.viewableContentWidth - display.screenOriginX local mRandom = math.random function spawnBox(event) if(boxSpawned == 0) then box = display.newImage("box.png") box.x = mRandom( \_L, \_R ) -- this is line 41 box.y = -50 boxSpawned = 1 physics.addBody(box, { density=1.0, friction=0.3, bounce=0.3 }) boxSpawned = 1 end end function scene:create( event ) local sceneGroup = self.view spawnBox() -- the rest of my code... end
This was working correctly while i was using the portrait screen orientation, now I’m using the landscape orientation and it’s a new project, does that have anything to do with it?