The error shows it breaks on line 245…
--Function to spawn an object local function spawn(params) local isSprite = params.isSprite or 0 if isSprite== 1 then --creaye a physics object from sprite set object = display.newSprite(params.spriteSheet, params.spriteSequence) else --print("Running on Game:spawn") object = display.newImage(params.image) end --Set the objects table to a table passed in by parameters object.objTable = params.objTable --Automatically set the table index to be inserted into the next available table index object.index = #object.objTable + 1 --Give the object a custom name object.myName = params.objectNamePrefix or "Object" --If the object should have a body create it, else dont. if params.hasBody then --Allow physics parameters to be passed by parameters: object.density = params.density or 0 object.friction = params.friction or 0 object.bounce = params.bounce or 0 object.isSensor = params.isSensor or false object.bodyType = params.bodyType or "dynamic" object.x=params.x or 0 object.y=params.y or 0 physics.addBody(object, object.bodyType, {density = object.density, friction = object.friction, bounce = object.bounce, isSensor = object.isSensor}) object:setLinearVelocity( params.linearVelocityX, 0 ) end --Add Value if is coin if params.objectNamePrefix == "Coin" then object.coinValue=params.thisCoinValue end --The objects group object.group = params.group or nil --If the function call has a parameter named group then insert it into the specified group object.group:insert(object) --Insert the object into the table at the specified index object.objTable[object.index] = object return object end
Here is the code that calls the function…
local function spawnFuselagePowerUp(event) if nextFuselagePowerUp==0 then local spawns = spawn( { objectNamePrefix ="FuselagePowerUp", image = "Images/FuselagePowerUp.png", objTable = FuselagePowerUpSpawnTable, hasBody = true, density=.01, friction = 0.4, bounce = 0, isSensor=true, bodyType = "kinematic", group = localGroup, x=600, y=math.random(heli.y-200, heli.y+200), linearVelocityX=-200 } ) nextFuselagePowerUp=storyboard.gameVars.FuselagePowerUpFrequency --Now remove FuselagePowerUps out of the screen --for i = #spawnTable, 1, -1 do -- if spawnTable[i] ~= nil then -- if spawnTable[i].x \<-300 then -- display.remove(spawnTable[i]) -- table.remove(spawnTable,i) -- end -- end --end else if #FuselagePowerUpSpawnTable\>0 then if FuselagePowerUpSpawnTable[1].x \<-100 then --print("Total FuselagePowerUps Before: "..#FuselagePowerUpSpawnTable) display.remove(FuselagePowerUpSpawnTable[1]) table.remove(FuselagePowerUpSpawnTable,1) --print("Total FuselagePowerUps After: "..#FuselagePowerUpSpawnTable) end end nextFuselagePowerUp=nextFuselagePowerUp-1 end --myText.text = "FuselagePowerUps: "..#spawnTable end
oh yeah, and the forward declarations (I should have posted this on top… )
--Create a table to hold our spawns local FuselagePowerUpSpawnTable={} --Vars local nextFuselagePowerUp=0