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.
local function gameover() 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
local function gameover() 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