Error Table Expected

Hello,

I have been following a tutorial located here: http://www.raywenderlich.com/9579/how-to-make-a-game-like-jetpack-joyride-using-levelhelper-and-spritehelper-corona-edition-part-3. I manage to get to the section where the mouse dies and the game over restart screen comes up. The mouse will die but you can not restart because of error. The error is listed below:

ERROR: table expected. If this is a function call, you might have used '.' instead of ':' message stack traceback: [C]: ? [C]: in function 'insert' ...ahmuskett/Documents/Corona/RocketMouse/gameLogic.lua:67: in function 'killPlayer' ...ahmuskett/Documents/Corona/RocketMouse/gameLogic.lua:83: in function '?' ...Corona/RocketMouse/LevelHelper/LevelHelperLoader.lua:987: in function <...corona><br> ?: in function <?:226>
I have uploaded my project here to help in determining what is wrong with my code: http://www.mediafire.com/download.php?87f62r3c9tc8eja.

Any help would be appreciated.

Thanks,
Elijah
[import]uid: 159438 topic_id: 34189 reply_id: 334189[/import] </…corona>

I tried to download it and it wouldn’t download. Can you paste in the code for gamelogic.lua and make sure to use <code> and </code> tags before and after your code?

Most likely you have a group:insert() call and what you’re inserting is not a valid object. [import]uid: 199310 topic_id: 34189 reply_id: 135994[/import]

[code]require “CiderDebugger”;
—Storyboard---------
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

–Global Variables
local parallaxNode = nil
local player = nil
local rocketFlame = nil
local playerVelocity = 0
local playerWasFlying = false
local playerShouldFly = false
local globalGroup = nil

–Score-----------------------------
local score = 0;
function scoreHitAtPosition(position, points)
score = score + points;
print ("Score: " … tostring(score))
end

–Mouse Coin Collision-------------------------
local function mouseCoinCollision(event)
–print("Sprite " … event.object1.lhUniqueName … " will collide with " … event.object2.lhUniqueName)

local coin = event.spriteB;

if(nil ~= coin) then
if(coin.alpha == 1.0) then
scoreHitAtPosition({x = coin.x, y = coin.y}, 100);
end
coin.alpha = 0.0;
end
end

—Player Is Dead----------------------------------
local playerIsDead = false;
local function killPlayer()
playerVelocity = 0.0;
playerShouldFly = false;
playerIsDead = true;
playerWasFlying = false;
rocketFlame.alpha = 0;
player:prepareAnimationNamed(“mouseDie”);
player:playAnimation();
parallaxNode:setSpeed(0);

local gameOverText = display.newText(“Game Over!”, 0, 0, native.systemFont, 32)
gameOverText:setTextColor(255, 0, 0)
gameOverText.x = display.viewableContentWidth / 2
gameOverText.y = display.viewableContentHeight /2 - 40

local restartText = display.newText(“Restart”, 0, 0, native.systemFont, 24)
restartText:setTextColor(255, 255, 255)
restartText.x = display.viewableContentWidth / 2
restartText.y = display.viewableContentHeight /2

local onRestartTouch = function(event)
if(event.phase == “began”)then
local storyboard = require(“storyboard”)
storyboard.gotoScene(“reset”)
Runtime:removeEventListener(“touch”, restartText);
end
end
restartText:addEventListener(“touch”, onRestartTouch)

globalGroup:insert(“gameOverText”)
globalGroup:insert(“restartText”)
end

–Lasers Collison---------------------------------------
local lasersThatNeedHandling = {};
local function mouseLaserCollision(event)
–print("Sprite " … event.object1.lhUniqueName … " is going collide with " … event.object2.lhUniqueName)

local laser = event.spriteB;

if(playerIsDead == true)then
return;
end

if(laser:currentAnimationFrame() ~= 1)then
killPlayer();
end

– If we make the laser a sensor, the callback will be called only once - at first collision.
– This is not good as we want to kill the player when the laser changes to active.
– So we make the laser sensor, so that the player and laser don’t collide, durring this collision.
– Then we keep track of the lasers that needs to change back to not being sensors
– and in the enterFrame we set back the lasers to isSensor = false

laser.isSensor = true;
lasersThatNeedHandling[#lasersThatNeedHandling+1] = laser;

end

----Start Collision---------------------------
local function setupCollisionHandling()

loader:registerBeginOrEndCollisionCallbackBetweenTags(LevelHelper_TAG.PLAYER,
LevelHelper_TAG.COIN,mouseCoinCollision)

loader:registerPreCollisionCallbackBetweenTags(LevelHelper_TAG.PLAYER, LevelHelper_TAG.LASER, mouseLaserCollision);

end

–Start Player Fly-----------------------------------------

function startPlayerFly()
if(playerIsDead == true)then
return
end
–print(“Start player fly”);
playerVelocity = 0.5
playerShouldFly = true
rocketFlame.alpha = 1
player:prepareAnimationNamed(“mouseFly”)
player:playAnimation()
end
–Cancel Player Fly----------------------
function cancelPlayerFly()
–print(“Cancel player fly”);
playerShouldFly = false
rocketFlame.alpha = 0
playerWasFlying = true
player:prepareAnimationNamed(“mouseFall”)
player:playAnimation()
playerVelocity = playerVelocity - 0.01

if(playerVelocity < 0) then
playerVelocity = 0
end

end

–Player Fly Function--------------------------------------
local function onTouch(event)
if(event.phase == “began”) then
startPlayerFly()
elseif(event.phase == “ended” or event.phase == “cancelled”) then
cancelPlayerFly()
end
end

–Player Impluse Function-----------------------------------------------
local onEnterFrame = function(event)

if(playerShouldFly == true) then
player:applyLinearImpulse(0, -playerVelocity, player.x, player.y)
playerVelocity = playerVelocity + 0.01

if(playerVelocity > 1.0) then
playerVelocity = 1.0
end
end

for i=1, #lasersThatNeedHandling do
lasersThatNeedHandling[i].isSensor = false;
end

lasersThatNeedHandling = {};

end
—Storyboard Enter Scene----------------------------
function scene:enterScene(event)
globalGroup = self.view

—Physics---------------------
local ui = require (“ui”)
local physics = require(“physics”)
local fps = require(“fps”)
physics.start()
–comment next line to disable debug drawing
–physics.setDrawMode( “hybrid” )
display.setStatusBar( display.HiddenStatusBar )
physics.setGravity(0, 10);

–Variables-------
parallaxNode = nil
player = nil
rocketFlame = nil
playerVelocity = 0;
playerIsDead = false;
playerWasFlying = false;
playerShouldFly = false;
lasersThatNeedHandling = nil
lasersThatNeedHandling = {};
score = 0;

require(“LevelHelper.LevelHelperLoader”)

application.LevelHelperSettings.directorGroup = self.view;

loader = LevelHelperLoader:initWithContentOfFile(“level03.plhs”)
loader:instantiateSprites();

parallaxNode = loader:parallaxWithUniqueName(“parallax1”);
if(nil == parallaxNode) then
print (“Could not find parallax.”)
end

player = loader:spriteWithUniqueName(“player”)
if(nil == player) then
print (“Could not find player.”)
end

rocketFlame = loader:spriteWithUniqueName(“flame”)
if(nil == rocketFlame) then
print (“Could not find rocket flame.”)
end

rocketFlame.alpha = 0

loader:useLevelHelperCollisionHandling()–instructs LH to take care of collisions

setupCollisionHandling()

Runtime:addEventListener(“touch”, onTouch)

Runtime:addEventListener(“enterFrame”, onEnterFrame)

end


function scene:exitScene(event)
local group = self.view

loader:removeSelf()
loader = nil;
player = nil;
Runtime:removeEventListener(“enterFrame”, onEnterFrame)
Runtime:removeEventListener(“touch”, onTouch)
physics.stop()
end


– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener(“enterScene”, scene)

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener(“exitScene”, scene)

return scene

[/code] [import]uid: 159438 topic_id: 34189 reply_id: 136029[/import]

>Most likely you have a group:insert() call and what you’re inserting is not a valid object.

Bingo.
You’re inserting strings, instead of the objects.

Try
globalGroup:insert( gameOverText)
globalGroup:insert( restartText ) [import]uid: 186251 topic_id: 34189 reply_id: 136032[/import]

Changed the strings to objects. When the mouse dies the objects don’t display now. Don’t know what to do next. There are no errors displaying. [import]uid: 159438 topic_id: 34189 reply_id: 136037[/import]

I’m confused as to why you have to createScene() but that’s neither here nor there.

I would start putting in some print statements and seeing where you’re getting to and what some values are that are being checked in comparison tests.

[import]uid: 199310 topic_id: 34189 reply_id: 136063[/import]

I tried to download it and it wouldn’t download. Can you paste in the code for gamelogic.lua and make sure to use <code> and </code> tags before and after your code?

Most likely you have a group:insert() call and what you’re inserting is not a valid object. [import]uid: 199310 topic_id: 34189 reply_id: 135994[/import]

[code]require “CiderDebugger”;
—Storyboard---------
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

–Global Variables
local parallaxNode = nil
local player = nil
local rocketFlame = nil
local playerVelocity = 0
local playerWasFlying = false
local playerShouldFly = false
local globalGroup = nil

–Score-----------------------------
local score = 0;
function scoreHitAtPosition(position, points)
score = score + points;
print ("Score: " … tostring(score))
end

–Mouse Coin Collision-------------------------
local function mouseCoinCollision(event)
–print("Sprite " … event.object1.lhUniqueName … " will collide with " … event.object2.lhUniqueName)

local coin = event.spriteB;

if(nil ~= coin) then
if(coin.alpha == 1.0) then
scoreHitAtPosition({x = coin.x, y = coin.y}, 100);
end
coin.alpha = 0.0;
end
end

—Player Is Dead----------------------------------
local playerIsDead = false;
local function killPlayer()
playerVelocity = 0.0;
playerShouldFly = false;
playerIsDead = true;
playerWasFlying = false;
rocketFlame.alpha = 0;
player:prepareAnimationNamed(“mouseDie”);
player:playAnimation();
parallaxNode:setSpeed(0);

local gameOverText = display.newText(“Game Over!”, 0, 0, native.systemFont, 32)
gameOverText:setTextColor(255, 0, 0)
gameOverText.x = display.viewableContentWidth / 2
gameOverText.y = display.viewableContentHeight /2 - 40

local restartText = display.newText(“Restart”, 0, 0, native.systemFont, 24)
restartText:setTextColor(255, 255, 255)
restartText.x = display.viewableContentWidth / 2
restartText.y = display.viewableContentHeight /2

local onRestartTouch = function(event)
if(event.phase == “began”)then
local storyboard = require(“storyboard”)
storyboard.gotoScene(“reset”)
Runtime:removeEventListener(“touch”, restartText);
end
end
restartText:addEventListener(“touch”, onRestartTouch)

globalGroup:insert(“gameOverText”)
globalGroup:insert(“restartText”)
end

–Lasers Collison---------------------------------------
local lasersThatNeedHandling = {};
local function mouseLaserCollision(event)
–print("Sprite " … event.object1.lhUniqueName … " is going collide with " … event.object2.lhUniqueName)

local laser = event.spriteB;

if(playerIsDead == true)then
return;
end

if(laser:currentAnimationFrame() ~= 1)then
killPlayer();
end

– If we make the laser a sensor, the callback will be called only once - at first collision.
– This is not good as we want to kill the player when the laser changes to active.
– So we make the laser sensor, so that the player and laser don’t collide, durring this collision.
– Then we keep track of the lasers that needs to change back to not being sensors
– and in the enterFrame we set back the lasers to isSensor = false

laser.isSensor = true;
lasersThatNeedHandling[#lasersThatNeedHandling+1] = laser;

end

----Start Collision---------------------------
local function setupCollisionHandling()

loader:registerBeginOrEndCollisionCallbackBetweenTags(LevelHelper_TAG.PLAYER,
LevelHelper_TAG.COIN,mouseCoinCollision)

loader:registerPreCollisionCallbackBetweenTags(LevelHelper_TAG.PLAYER, LevelHelper_TAG.LASER, mouseLaserCollision);

end

–Start Player Fly-----------------------------------------

function startPlayerFly()
if(playerIsDead == true)then
return
end
–print(“Start player fly”);
playerVelocity = 0.5
playerShouldFly = true
rocketFlame.alpha = 1
player:prepareAnimationNamed(“mouseFly”)
player:playAnimation()
end
–Cancel Player Fly----------------------
function cancelPlayerFly()
–print(“Cancel player fly”);
playerShouldFly = false
rocketFlame.alpha = 0
playerWasFlying = true
player:prepareAnimationNamed(“mouseFall”)
player:playAnimation()
playerVelocity = playerVelocity - 0.01

if(playerVelocity < 0) then
playerVelocity = 0
end

end

–Player Fly Function--------------------------------------
local function onTouch(event)
if(event.phase == “began”) then
startPlayerFly()
elseif(event.phase == “ended” or event.phase == “cancelled”) then
cancelPlayerFly()
end
end

–Player Impluse Function-----------------------------------------------
local onEnterFrame = function(event)

if(playerShouldFly == true) then
player:applyLinearImpulse(0, -playerVelocity, player.x, player.y)
playerVelocity = playerVelocity + 0.01

if(playerVelocity > 1.0) then
playerVelocity = 1.0
end
end

for i=1, #lasersThatNeedHandling do
lasersThatNeedHandling[i].isSensor = false;
end

lasersThatNeedHandling = {};

end
—Storyboard Enter Scene----------------------------
function scene:enterScene(event)
globalGroup = self.view

—Physics---------------------
local ui = require (“ui”)
local physics = require(“physics”)
local fps = require(“fps”)
physics.start()
–comment next line to disable debug drawing
–physics.setDrawMode( “hybrid” )
display.setStatusBar( display.HiddenStatusBar )
physics.setGravity(0, 10);

–Variables-------
parallaxNode = nil
player = nil
rocketFlame = nil
playerVelocity = 0;
playerIsDead = false;
playerWasFlying = false;
playerShouldFly = false;
lasersThatNeedHandling = nil
lasersThatNeedHandling = {};
score = 0;

require(“LevelHelper.LevelHelperLoader”)

application.LevelHelperSettings.directorGroup = self.view;

loader = LevelHelperLoader:initWithContentOfFile(“level03.plhs”)
loader:instantiateSprites();

parallaxNode = loader:parallaxWithUniqueName(“parallax1”);
if(nil == parallaxNode) then
print (“Could not find parallax.”)
end

player = loader:spriteWithUniqueName(“player”)
if(nil == player) then
print (“Could not find player.”)
end

rocketFlame = loader:spriteWithUniqueName(“flame”)
if(nil == rocketFlame) then
print (“Could not find rocket flame.”)
end

rocketFlame.alpha = 0

loader:useLevelHelperCollisionHandling()–instructs LH to take care of collisions

setupCollisionHandling()

Runtime:addEventListener(“touch”, onTouch)

Runtime:addEventListener(“enterFrame”, onEnterFrame)

end


function scene:exitScene(event)
local group = self.view

loader:removeSelf()
loader = nil;
player = nil;
Runtime:removeEventListener(“enterFrame”, onEnterFrame)
Runtime:removeEventListener(“touch”, onTouch)
physics.stop()
end


– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener(“enterScene”, scene)

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener(“exitScene”, scene)

return scene

[/code] [import]uid: 159438 topic_id: 34189 reply_id: 136029[/import]

>Most likely you have a group:insert() call and what you’re inserting is not a valid object.

Bingo.
You’re inserting strings, instead of the objects.

Try
globalGroup:insert( gameOverText)
globalGroup:insert( restartText ) [import]uid: 186251 topic_id: 34189 reply_id: 136032[/import]

Changed the strings to objects. When the mouse dies the objects don’t display now. Don’t know what to do next. There are no errors displaying. [import]uid: 159438 topic_id: 34189 reply_id: 136037[/import]

I’m confused as to why you have to createScene() but that’s neither here nor there.

I would start putting in some print statements and seeing where you’re getting to and what some values are that are being checked in comparison tests.

[import]uid: 199310 topic_id: 34189 reply_id: 136063[/import]