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 !
(sorry i’m french so my english isn’t perfect ! ;) )