Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Attempt to call upvalue 'gameover' (a table value) error
Started by supersteveninoz Aug 30 2014 04:32 AM

- - - - -
2 replies to this topic
error corona sdk

Best Answer Rob Miracle , 30 August 2014 - 07:13 AM

This one is pretty easy. 

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

 

and you should be all set.

Rob

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

supersteveninoz

[GLOBAL: userInfoPane.html]
supersteveninoz
  • Observer

  • 2 posts
  • Corona SDK

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 :)

Attached Files



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

  Best Answer

This one is pretty easy. 

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

 

and you should be all set.

Rob



[TOPIC: post.html]
#3

supersteveninoz

[GLOBAL: userInfoPane.html]
supersteveninoz
  • Observer

  • 2 posts
  • Corona SDK

Thanks!
I can't believe I missed that haha

It works great now! 

Cheers :)




[topic_controls]
[/topic_controls]