Why am I getting this error?

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?

This line is probably failing to make a ‘box’

 box = display.newImage("box.png")

Look in the logs before the error to see if you get a warning about not making the box or not finding an image.

Check the spelling of your image name, case, and location.

Thanks for your answer but I already fixed it, my image was in a folder like this " assets/box.png".

I guess I wasn’t concentrated enough. Sorry for the inconvenience.

Thank you for sharing your solution!

Rob

This line is probably failing to make a ‘box’

 box = display.newImage("box.png")

Look in the logs before the error to see if you get a warning about not making the box or not finding an image.

Check the spelling of your image name, case, and location.

Thanks for your answer but I already fixed it, my image was in a folder like this " assets/box.png".

I guess I wasn’t concentrated enough. Sorry for the inconvenience.

Thank you for sharing your solution!

Rob