problem with "y" coordinate

Hi you all, in my physics-based game, I get the following error when my character’s y coordinate is higher than the screen’s height

[lua]

File: …nzoestienne/Desktop/prova director/gameWithSound.lua

Line: 142

Attempt to index upvalue ‘player’ (a nil value)

stack traceback:

    [C]: ?

    …nzoestienne/Desktop/prova director/gameWithSound.lua:142: in function <…nzoestienne/Desktop/prova director/gameWithSound.lua:140>

    ?: in function <?:218>

 

[/lua]

 

The code I’ve used to do that is 

 

 

[lua] –START: GAME OVER 

local statusText = display.newText("", _W/2, _H/2-100, “FOO”, 32)

local timeText = display.newText("", _W/2, _H/2, “FOO”, 32)

local function adjustText()

if player.y > _H then

statusText.text = "Game Over"

media.playSound( “suoni/gameover.wav” )

local function replacePlayer()

player:removeSelf()

player = nil

end

timer.performWithDelay( 100, replacePlayer )

statusText:setTextColor(255, 255, 0)

Runtime:removeEventListener(“enterFrame”, scroll)

else

     statusText.text = ""

end

end

Runtime:addEventListener(“enterFrame”, adjustText)[/lua]

 

where line 142 is " if player.y > _H then"

 

and line 140 is "local function adjustText()"

How can I fix this bug?

Thank you so much! :smiley:

I think if you do print(player.y) on line 139 you will get a nil value.  The problem seems to reside in the player object.

Thanks! You have been very helpful, now it works fine :slight_smile:

I think if you do print(player.y) on line 139 you will get a nil value.  The problem seems to reside in the player object.

Thanks! You have been very helpful, now it works fine :slight_smile: