Corona Runtime Error

Hello,

I have a problem that i don’t understand, when I launch my project with Corona SDK this message appears :

playGame.lua:18:ERROR:table expected. If this is a function call, you might have used ‘.’ instead of ‘:’

stack traceback :

     [C]: in function.lua:18: in function <playGame.lua:5>

     ?: in function ‘dispatchEvent’

     ?:in function ‘gotoScene’

     mainMenu.lua:11: in function mainMenu.lua:9>

     ?: in function <?:221>

I don’t understand what it mean so i need help.

I have 3 lua : main.lua / mainMenu.lua / playGame.lua

_ main.lua : _

local composer = require ( “composer” )

composer.recycleOnSceneChange = true

composer.gotoScene(“mainMenu”, {effect = “fade”, time = 1500})

_ mainMenu.lua : _

local composer = require( “composer” )

local scene = composer.newScene()

function scene:create( event )

     local sceneGroup = self.view

     local playD = display.newText (“Play”, 160, 240, font, 30)

     playD:setFillColor(200,200,200)

     sceneGroup:insert (playD)

     local function playDListener (event)

          if (event.phase == “began”) then

              composer.gotoScene ( “playGame”, {effect = “fade”, time = 500})

          end

          return true

     end

     playD:addEventListener (“touch”, playDListener)

end

scene:addEventListener (“create”, scene)

return scene

playGame.lua :

local composer = require("composer") local scene = composer.newScene() local physics = require ("physics") physics.start () function scene:create(event) local sceneGroup = self.view local background = display.newRect (160, 240, 320, 480) background:setFillColor (127/255,255/255,212/255) sceneGroup:insert (background) local myObstacles = {} local pIntX = 360 local pBotY = 340 for i=1, 4 do myObstacles[i] = {} pBot = display.newRect (pIntX, pBotY, 40, 280) pTop = display.newRect (pIntX, (pBotY-360), 40, 280) sceneGroup:insert("myObstacles[i].pBot") sceneGroup:insert("myObstacles[i].pTop") pIntX = pIntX + 120 pBotY = pBotY + 40 end local fakyBird = display.newRect (50, 50, 20, 20) fakyBird:setFillColor(0.3,0.3,0.3) sceneGroup:insert (fakyBird) local myScore = 0 local myScoreDisplay = display.newText ("Score: "..myScore, 260, 30, font, 24) myScoreDisplay:setFillColor (0,0,0) physics.addBody (fakyBird) fakyBird.gravityScale = 0 fakyBird.isFixedRotation = true fakyBird.isSensor = true fakyBird.ID = "Bird" for i=1, #myObstacle do myObstacle[i].pBot.ID = "Crash" myObstacle[i].pTop.ID = "Crash" physics.addBody (myObstacle[i].pBot, "static") physics.addBody (myObstacle[i].pTop, "static") end local xDelta = 2 local fakyYDelta = 7 local fakyFlapDelta = 0 local function flapBird (event) if (event.phase == "began") then fakyFlapDelta =13 end end local function onUpdate (event) for i=1, #myObstacle do myObstacle[i].pBot.x = myObstacle[i].pBot.x - xDelta myObstacle[i].pTop.x = myObstacle[i].pBot.x - xDelta if (myObstacle[i].pBot.x \<= -20) then myObstacle[i].pBot.x = 460 myScore = myScore + 1 myScoreDisplay.text = "Score: "..myScore end end if (fakyFlapDelta \> 0) then fakyBird.y = fakyBird.y - fakyFlapDelta fakyFlapDelta = fakyFlapDelta - 0.8 end fakyBird.y = fakyBird.y + fakyYDelta if (fakyBird.y \< -40) then endGame () elseif (fakyBird.y \> 520) then endGame () end end local function onLocalCollision (self, event) if (event.phase == "began") then if (self.ID == "Bird" and event.other.ID == "Crash") then endGame () end end end function endGame () fakyBird:removeEventListener( "collision", fakyBird) Runtime:removeEventListener ("enterFrame", onUpdate) background:removeEventListener ("touch", flapBird) local promptEnd = display.newText ("You Lost !", 160, 100, font, 32) promptEnd:setFillColor (0,0,0) local promptReplay = display.newText ("Play Again", 160, 240, font, 32) promptReplay:setFillColor(0,0,0) sceneGroup:insert (promptEnd) sceneGroup:insert (promptReplay) local function replay(event) if (event.phase == "began") then composer.gotoScene ("mainMenu", {effect = "fade", time = 1000}) end end promptReplay:addEventListener ("touch", replay) end fakyBird.collision = onLocalCollision fakyBird:addEventListener("collision", fakyBird) Runtime:addEventListener ("enterFrame", onUpdate) background:addEventListener ("touch", flapBird) end scene:addEventListener("create", scene) return scene

(Sorry there is no numbers of lines but the probleme is at the beginning at : sceneGroup:insert(“myObstacles[i].pBot”)

sceneGroup:insert(“myObstacles[i].pTop”) )

Thaks for your help !  :slight_smile:

(sorry i’m french so my english isn’t perfect ! ;) )

Hi @lucas.chalan,

This is a simple syntax error. In this line…

[lua]

sceneGroup:insert(“myObstacles[i].pBot”)

[/lua]

…because you have surrounded the argument with quotes ("), you are telling Corona to insert a string into the sceneGroup. This is not valid: you must insert a Corona display object. See the difference here:

[lua]

sceneGroup:insert( myObstacles[i].pBot )

[/lua]

Take care,

Brent

Hi Brent,

The problem is exactly the same without quotes (") …

I have already try tome make without them but the error message is the same …

Thanks for your help !

Lucas

Hi Lucas,

You are not declaring your myObstacles table properly in lines 15-18.  Your ending curly brace needs to be after the definitions for pBot and pTop

 myObstacles[i] = { pBot = display.newRect (pIntX, pBotY, 40, 280), pTop = display.newRect (pIntX, (pBotY-360), 40, 280) }

-Tony

Edited to fix missing comma at end of line 16

Hi Tony,

I understand and that’s logical but it doesn’t want it … when I put ‘}’ alone in line 18 this error message appears :

error loading module ‘playGame’ from file ‘playGame.lua’ :

                playGame.lua:17: ‘}’ expected (to close ‘{’ at line 15) near

‘pTop’

stack traceback

     [C]: in function ‘error’

      ?:in function ‘gotoScene’

     mainMenu.lua:11: in function mainMenu.lua:9>

     ?: in function <?:221>

 

 

I’m using the software “Notepad++” maybe it’s not a good one …

What others softwares can I use to edit in lua ?

 

Thanks for your answers !

Lucas

Hi,

I suspect there’s a missing comma at the end of line 16?

Cheers,

Simon

Dixon Court Entertainment

Thank you , DixonCourt.  I edited my post and fixed the inline code above.

Best regards,

Tony

Hi evrybody,

I don’t understand where is the problem with a comma in line 16 …

Can you show me the good code for line 15 to 19 please ?

Thank you for your patience ! :wink:

Lucas

Hi @lucas.chalan,

This is a simple syntax error. In this line…

[lua]

sceneGroup:insert(“myObstacles[i].pBot”)

[/lua]

…because you have surrounded the argument with quotes ("), you are telling Corona to insert a string into the sceneGroup. This is not valid: you must insert a Corona display object. See the difference here:

[lua]

sceneGroup:insert( myObstacles[i].pBot )

[/lua]

Take care,

Brent

Hi Brent,

The problem is exactly the same without quotes (") …

I have already try tome make without them but the error message is the same …

Thanks for your help !

Lucas

Hi Lucas,

You are not declaring your myObstacles table properly in lines 15-18.  Your ending curly brace needs to be after the definitions for pBot and pTop

 myObstacles[i] = { pBot = display.newRect (pIntX, pBotY, 40, 280), pTop = display.newRect (pIntX, (pBotY-360), 40, 280) }

-Tony

Edited to fix missing comma at end of line 16

Hi Tony,

I understand and that’s logical but it doesn’t want it … when I put ‘}’ alone in line 18 this error message appears :

error loading module ‘playGame’ from file ‘playGame.lua’ :

                playGame.lua:17: ‘}’ expected (to close ‘{’ at line 15) near

‘pTop’

stack traceback

     [C]: in function ‘error’

      ?:in function ‘gotoScene’

     mainMenu.lua:11: in function mainMenu.lua:9>

     ?: in function <?:221>

 

 

I’m using the software “Notepad++” maybe it’s not a good one …

What others softwares can I use to edit in lua ?

 

Thanks for your answers !

Lucas

Hi,

I suspect there’s a missing comma at the end of line 16?

Cheers,

Simon

Dixon Court Entertainment

Thank you , DixonCourt.  I edited my post and fixed the inline code above.

Best regards,

Tony

Hi evrybody,

I don’t understand where is the problem with a comma in line 16 …

Can you show me the good code for line 15 to 19 please ?

Thank you for your patience ! :wink:

Lucas