attempt to perform arithmetic on global 'screenLeft' (a nil value)

Hi, 

In the code that I am using in the course that I am taking, I am receiving the following error: attempt to perform arithmetic on global ‘screenLeft’ (a nil value) from the following function. Can you tell me if I am doing something wrong? 
Thanks!

 

function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. local backBtn = widget.newButton { label = "Back", x = screenLeft + 10, y = screenTop + 10, onRelease=doButton } backBtn.anchorX = 0 backBtn.anchorY = 0 sceneGroup:insert(backBtn) end

Hi,

That error simply means screenLeft hasn’t been defined. As far as I know it’s not an inbuilt property? Have you declared screenLeft earlier in your code? If you want it to return the x-coordinate of the left side of the screen then you will need to define it as such, although the point (0,0) is always the top left corner of the screen at startup, so screenLeft and screenTop will both be 0 (unless you scale e.g. letterbox, in which case you’ll want to check out the screenOrigin functions).

Cheers,

Simon

Dixon Court Entertainment

That was it. Thanks for the help, Simon!

Hi,

That error simply means screenLeft hasn’t been defined. As far as I know it’s not an inbuilt property? Have you declared screenLeft earlier in your code? If you want it to return the x-coordinate of the left side of the screen then you will need to define it as such, although the point (0,0) is always the top left corner of the screen at startup, so screenLeft and screenTop will both be 0 (unless you scale e.g. letterbox, in which case you’ll want to check out the screenOrigin functions).

Cheers,

Simon

Dixon Court Entertainment

That was it. Thanks for the help, Simon!