Attempt to call upvalue 'gameover' (a table value) error

Hi

I’m using Corona SDK for a school assignment and basing my simple game off a tutorial by J. A. Whye : https://www.udemy.com/game-development-crash-course/?dtcode=Pj2adTk1oopb#/
The game runs fine the first play and you’re able to restart the game if you lose.

But on the second play when you lose it results in this error:
 

Runtime error

…\castleapp\main.lua:94: attempt to call upvalue ‘gameover’ (a table value)

stack traceback:

…\castleapp\main.lua:94: in function ‘spawnblob’

…\castleapp\main.lua:117: in function …\castleapp\main.lua:114>

(tail call): ?

?: in function <?:498>

?: in function <?:221>

I have no idea why, I’m just a newbie (so my code could look very bad to you sorry) and would appreciate someone being able to help me resolve this problem. 

Thanks Stevo :slight_smile:

This one is pretty easy. 

local function gameover() &nbsp;&nbsp;&nbsp; gameover = display.newText( "YOU FAILED", 0, 0, "Helvetica" , 40 )

You declare a function using the same name called gameover.  Inside that function you overwrite gameover with a display object, so it’s no longer a function but an object (table value).  When you go to run gameover() a second time, it no longer exists as a function.

Simply rename your text object to something like:   gameoverText

and don’t forget to adjust your pre-declaration at the top:  local gameover    to    local gameoverText

and you should be all set.

Rob

Thanks!
I can’t believe I missed that haha

It works great now! 

Cheers :slight_smile:

This one is pretty easy. 

local function gameover() &nbsp;&nbsp;&nbsp; gameover = display.newText( "YOU FAILED", 0, 0, "Helvetica" , 40 )

You declare a function using the same name called gameover.  Inside that function you overwrite gameover with a display object, so it’s no longer a function but an object (table value).  When you go to run gameover() a second time, it no longer exists as a function.

Simply rename your text object to something like:   gameoverText

and don’t forget to adjust your pre-declaration at the top:  local gameover    to    local gameoverText

and you should be all set.

Rob

Thanks!
I can’t believe I missed that haha

It works great now! 

Cheers :slight_smile: