Weird Error? Storyboard makes game crash??

When I run this game with storyboard I get this error after the tutorial level is complete. Below are my codes. I have my main pointing to start, then tutorial. I have my onCollision set to then move to level one. Thats where the problems start. Level one loads and scrolls and my missiles work but the rocket does not move and doesn’t collide with any missles. From there I can’t do anything. If i point my start to level 1 it does the same thing for lvl 2. Now if I run any of these codes by themselves starting from main they all work fine. Any idea of whats going wrong?

Error Message: 2013-01-14 14:11:34.981 Corona Simulator[4117:707] Runtime error
…ions/CoronaSDK/SampleCode/mkjt88/Scroller/level1.lua:102: attempt to call method ‘applyForce’ (a nil value)
stack traceback:
[C]: in function ‘applyForce’
…ions/CoronaSDK/SampleCode/mkjt88/Scroller/level1.lua:102: in function <…ions>
?: in function <?:229>

[lua]-----------------------------------------------------------------------------------------

– Main.lua

-----------------------------------------------------------------------------------------

display.setStatusBar(display.HiddenStatusBar)

local storyboard = require "storyboard"
storyboard.gotoScene(“start”)

-----------------------------------------------------------------------------------------

– start.lua

-----------------------------------------------------------------------------------------

screenW = display.contentWidth
screenH = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

local phyics = require “physics” ; physics.setDrawMode( “normal” )
physics.start()

function scene:createScene(event)
local screenGroup = self.view
background = display.newImage(“startScreen.png”)
screenGroup:insert(background)
end

function start(event)
if event.phase == “began” then
storyboard.gotoScene(“tutorial”)
end
end

function scene:enterScene(event)

background:addEventListener(“touch”, start)
end

function scene:exitScene(event)

background:removeEventListener(“touch”, start)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene

-----------------------------------------------------------------------------------------

– tutorial.lua

-----------------------------------------------------------------------------------------

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

screenW = display.contentWidth
screenH = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)

local phyics = require “physics” ; physics.setDrawMode( “normal” )
physics.start()

– Boundaries
ceiling = display.newRect (0, screenH - 350, screenW, 0)
floor = display.newRect (0, screenH + 30, screenW, 0)

– Make Walls Physical
physics.addBody (ceiling, “static”, {friction = .2, bounce = .1})
physics.addBody (floor, “static”, {friction = .2, bounce = .1})

function scene:createScene(event)
local screenGroup = self.view

– Background Images
background1 = display.newImage(“background.png”)
background1:setReferencePoint(display.BottomLeftReferencePoint)
background1.x = 0
background1.y = 320
background1.speed = 8
screenGroup:insert(background1)
background2 = display.newImage(“background.png”)
background2:setReferencePoint(display.BottomLeftReferencePoint)
background2.x = 480
background2.y = 320
background2.speed = 8
screenGroup:insert(background2)

– Rocket
rocket = display.newImage(“rocket.png”)
rocket.x = 100
rocket.y = 160
physics.addBody(rocket, “dynamic”, {density = .1, friction = .5, radius = 25})
screenGroup:insert(rocket)

– Missiles
missile1 = display.newImage(“missile.png”)
missile1.x = 500
missile1.y = 100
missile1.speed = math.random(4,12)
missile1.initY = missile1.y
missile1.amp = math.random(1,100)
missile1.angle = math.random(1,360)
physics.addBody(missile1, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile1)

missile2 = display.newImage(“missile.png”)
missile2.x = 500
missile2.y = 250
missile2.speed = math.random(7,15)
missile2.initY = missile2.y
missile2.amp = math.random(1,100)
missile2.angle = math.random(1,360)
physics.addBody(missile2, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile2)

end

----------- Functions

function onTouch(event)
if event.phase == “began” then
rocket.enterFrame = activateRocket
Runtime:addEventListener(“enterFrame”, rocket)
end

if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, rocket)
end
end
function scrollField(self,event)
if self.x < -475 then
self.x = 475
else
self.x = self.x - self.speed
end
end

function activateRocket(self,event)
self:applyForce(0, -15, self.x, self.y)
end

function moveMissile(self,event)
if self.x < -50 then
self.x = 500
self.y = math.random(20,300)
self.speed = math.random(2,5)
self.amp = math.random(20,50)
self.angle = math.random(1,200)
else
self.x = self.x - self.speed
self.angle = self.angle + .1
self.y = self.amp * math.sin(self.angle)+self.initY
end
end

function onCollision(event)
if event.phase == “began” then
storyboard.gotoScene(“level1”, “fade”, 400)
end
end
function scene:enterScene(event)

background1.enterFrame = scrollField
Runtime:addEventListener(“enterFrame”, background1)

background2.enterFrame = scrollField
Runtime:addEventListener(“enterFrame”, background2)

missile1.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile1)

missile2.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile2)

Runtime:addEventListener(“touch”, onTouch)

Runtime:addEventListener(“collision”, onCollision)

end

function scene:exitScene(event)

Runtime:removeEventListener(“enterFrame”, background1)

Runtime:removeEventListener(“enterFrame”, background2)

Runtime:removeEventListener(“enterFrame”, missile1)

Runtime:removeEventListener(“enterFrame”, missile2)

Runtime:removeEventListener(“touch”, onTouch)

Runtime:removeEventListener(“collision”, onCollision)
end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene

-----------------------------------------------------------------------------------------

– level1.lua

-----------------------------------------------------------------------------------------

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

screenW = display.contentWidth
screenH = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)

local phyics = require “physics” ; physics.setDrawMode( “normal” )
physics.start()

– Boundaries
ceiling = display.newRect (0, screenH - 350, screenW, 0)
ceiling.name = "ceiling"
floor = display.newRect (0, screenH + 30, screenW, 0)
floor.name = “floor”

– Make Walls Physical
physics.addBody (ceiling, “static”, {friction = .2, bounce = .1})
physics.addBody (floor, “static”, {friction = .2, bounce = .1})

function scene:createScene(event)

local screenGroup = self.view

– Background Images

backgroundKep = display.newImage(“bgKep.png”, true)
backgroundKep:setReferencePoint(display.BottomLeftReferencePoint)
backgroundKep.x = 0
backgroundKep.y = 320
backgroundKep.speed = 5
screenGroup:insert(backgroundKep)

backgroundKep2 = display.newImage(“bgKep.png”, true)
backgroundKep2:setReferencePoint(display.BottomLeftReferencePoint)
backgroundKep2.x = 6077
backgroundKep2.y = 320
backgroundKep2.speed = 5
screenGroup:insert(backgroundKep2)

– Rocket
rocket = display.newImage(“rocket.png”)
rocket.x = 100
rocket.y = 160
rocket.name = “rocket”
physics.addBody(rocket, “dynamic”, {density = .1, friction = .5, radius = 20})
screenGroup:insert(rocket)

– Missiles
missile1 = display.newImage(“missile.png”)
missile1.x = 500
missile1.y = 100
missile1.speed = math.random(4,12)
missile1.initY = missile1.y
missile1.amp = math.random(1,100)
missile1.angle = math.random(1,360)
missile1.name = “missile1”
physics.addBody(missile1, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile1)

missile2 = display.newImage(“missile.png”)
missile2.x = 500
missile2.y = 250
missile2.speed = math.random(7,15)
missile2.initY = missile2.y
missile2.amp = math.random(1,100)
missile2.angle = math.random(1,360)
missile2.name = “missile2”
physics.addBody(missile2, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile2)

end

------ Functions

function onTouch(event)
if event.phase == “began” then
rocket.enterFrame = activateRocket
Runtime:addEventListener(“enterFrame”, rocket)
end

if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, rocket)
end
end

local function scrollBack(self,event)
if self.x < -6077 then
self.x = 6077
else
self.x = self.x - self.speed
end
end

function activateRocket(self,event)
self:applyForce(0, -10, self.x, self.y)
end

local function moveMissile(self,event)
if self.x < -50 then
self.x = 500
self.y = math.random(20,300)
self.speed = math.random(2,5)
self.amp = math.random(20,50)
self.angle = math.random(1,200)
else
self.x = self.x - self.speed
self.angle = self.angle + .1
self.y = self.amp * math.sin(self.angle)+self.initY
end
end

function onCollision(event)
if event.phase == “began” then
storyboard.gotoScene(“level2”, “fade”, 400)
end
end
function scene:enterScene(event)

backgroundKep.enterFrame = scrollBack
Runtime:addEventListener(“enterFrame”, backgroundKep)

backgroundKep2.enterFrame = scrollBack
Runtime:addEventListener(“enterFrame”, backgroundKep2)

missile1.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile1)

missile2.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile2)

Runtime:addEventListener(“touch”, onTouch)

Runtime:addEventListener(“collision”, onCollision)

end

function scene:exitScene(event)

Runtime:removeEventListener(“enterFrame”, backgroundKep)

Runtime:removeEventListener(“enterFrame”, backgroundKep2)

Runtime:removeEventListener(“enterFrame”, missile1)

Runtime:removeEventListener(“enterFrame”, missile2)

Runtime:removeEventListener(“touch”, onTouch)

Runtime:removeEventListener(“collision”, onCollision)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene
-----------------------------------------------------------------------------------------

– level2.lua

-----------------------------------------------------------------------------------------

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

screenW = display.contentWidth
screenH = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)

local phyics = require “physics” ; physics.setDrawMode( “normal” )
physics.start()

– Boundaries
ceiling = display.newRect (0, screenH - 350, screenW, 0)
ceiling.name = "ceiling"
floor = display.newRect (0, screenH + 30, screenW, 0)
floor.name = “floor”

– Make Walls Physical
physics.addBody (ceiling, “static”, {friction = .2, bounce = .1})
physics.addBody (floor, “static”, {friction = .2, bounce = .1})

function scene:createScene(event)

local screenGroup = self.view

– Background Images

backgroundInc = display.newImage(“bgInc.png”, true)
backgroundInc:setReferencePoint(display.BottomLeftReferencePoint)
backgroundInc.x = 0
backgroundInc.y = 320
backgroundInc.speed = 5
screenGroup:insert(backgroundInc)

backgroundInc2 = display.newImage(“bgInc.png”, true)
backgroundInc2:setReferencePoint(display.BottomLeftReferencePoint)
backgroundInc2.x = 8190
backgroundInc2.y = 320
backgroundInc2.speed = 5
screenGroup:insert(backgroundInc2)

– Rocket
rocket = display.newImage(“rocket.png”)
rocket.x = 100
rocket.y = 160
rocket.name = “rocket”
physics.addBody(rocket, “dynamic”, {density = .1, friction = .5, radius = 20})
screenGroup:insert(rocket)

– Missiles
missile1 = display.newImage(“missile.png”)
missile1.x = 500
missile1.y = 100
missile1.speed = math.random(4,12)
missile1.initY = missile1.y
missile1.amp = math.random(1,100)
missile1.angle = math.random(1,360)
missile1.name = “missile1”
physics.addBody(missile1, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile1)

missile2 = display.newImage(“missile.png”)
missile2.x = 500
missile2.y = 250
missile2.speed = math.random(7,15)
missile2.initY = missile2.y
missile2.amp = math.random(1,100)
missile2.angle = math.random(1,360)
missile2.name = “missile2”
physics.addBody(missile2, “static”, {density = .1, bounce = .1, friction = .2})
screenGroup:insert(missile2)

end

----- Functions

function onTouch(event)
if event.phase == “began” then
rocket.enterFrame = activateRocket
Runtime:addEventListener(“enterFrame”, rocket)
end

if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, rocket)
end
end

local function scrollBack(self,event)
if self.x < -8190 then
self.x = 8190
else
self.x = self.x - self.speed
end
end

function activateRocket(self,event)
self:applyForce(0, -10, self.x, self.y)
end

local function moveMissile(self,event)
if self.x < -50 then
self.x = 500
self.y = math.random(20,300)
self.speed = math.random(2,5)
self.amp = math.random(20,50)
self.angle = math.random(1,200)
else
self.x = self.x - self.speed
self.angle = self.angle + .1
self.y = self.amp * math.sin(self.angle)+self.initY
end
end

function onCollision(event)
if event.phase == “began” then
storyboard.gotoScene(“restart”, “fade”, 400)
end
end
function scene:enterScene(event)

backgroundInc.enterFrame = scrollBack
Runtime:addEventListener(“enterFrame”, backgroundInc)

backgroundInc2.enterFrame = scrollBack
Runtime:addEventListener(“enterFrame”, backgroundInc2)

missile1.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile1)

missile2.enterFrame = moveMissile
Runtime:addEventListener(“enterFrame”, missile2)

Runtime:addEventListener(“touch”, onTouch)

Runtime:addEventListener(“collision”, onCollision)

end

function scene:exitScene(event)

Runtime:removeEventListener(“enterFrame”, backgroundInc)

Runtime:removeEventListener(“enterFrame”, backgroundInc2)

Runtime:removeEventListener(“enterFrame”, missile1)

Runtime:removeEventListener(“enterFrame”, missile2)

Runtime:removeEventListener(“touch”, onTouch)

Runtime:removeEventListener(“collision”, onCollision)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene
-----------------------------------------------------------------------------------------

– Restart.lua

-----------------------------------------------------------------------------------------

screenW = display.contentWidth
screenH = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

local phyics = require “physics” ; physics.setDrawMode( “normal” )
physics.start()
function scene:createScene(event)
local screenGroup = self.view
background = display.newImage(“restart.png”)
screenGroup:insert(background)
end

function start(event)
if event.phase == “began” then
storyboard.gotoScene(“main”)
end
end

function scene:enterScene(event)

background:addEventListener(“touch”, start)
end

function scene:exitScene(event)

background:removeEventListener(“touch”, start)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene [import]uid: 20272 topic_id: 34942 reply_id: 334942[/import] </…ions>

You probably should call physics.stop() before changing scenes from level1, if not those functions are going to fire after the scene is moved out of the way.
[import]uid: 199310 topic_id: 34942 reply_id: 138924[/import]

Where should that be added? I tried it at the end of my functions, in my exit scene and at the bottom of the page… i get the same errors and my rocket doesn’t move. [import]uid: 20272 topic_id: 34942 reply_id: 138935[/import]

exitScene() would be a good place. [import]uid: 199310 topic_id: 34942 reply_id: 138937[/import]

Thank you… Right now if I start with main and gotoScene “start”, then click to gotoScene “tutorial” The background loads and scrolls and the missles move but the rocket stays put and get this error.

Copyright © 2009-2012 C o r o n a L a b s I n c .
2013-01-15 06:37:25.323 Corona Simulator[4117:707] Version: 2.0.0
2013-01-15 06:37:25.323 Corona Simulator[4117:707] Build: 2012.971
2013-01-15 06:37:25.324 Corona Simulator[4117:707] The file sandbox for this project is located at the following folder:
(/Users/mkjt88/Library/Application Support/Corona Simulator/Scroller-0925D93CFA3CB11CBDED963F819C3755)
2013-01-15 06:37:39.472 Corona Simulator[4117:707] ERROR: physics.start() has not been called.
2013-01-15 06:37:39.474 Corona Simulator[4117:707] ERROR: physics.start() has not been called.
2013-01-15 06:37:39.475 Corona Simulator[4117:707] ERROR: physics.start() has not been called.

I cannot find a way around it now and I still get my original messages on lvl1 and 2. If I call lvl1 or 2 from main it works fine… but just not if one is played ahead of another. Any ideas? [import]uid: 20272 topic_id: 34942 reply_id: 138986[/import]

Hi @mkjt88,

I glanced at your previous request on this issue last Sunday. While I’d like to solve it for you (and the community would certainly like to help too), it’s somewhat difficult when you provide several hundred lines of code and 3-4 Storyboard scenes in code. Pasting your code certainly helps us solve problems, but too much code requires a “dedicated soul” and a sizable amount of time to really sort through it all, line by line, to figure out what’s going on.

My sincere suggestion is that you roll back your code to just one Storyboard scene with perhaps one or two physics objects. From that, study how Storyboard phases and methods work, and when you should perform various operations and processes. When you stumble upon one problem, focus on solving that first. If it’s still elusive after a due process of problem solving, post to the forums and ask just about that specific issue. Provide only the code related to that, if you can isolate it.

I know it’s frustrating sometimes, but it’s the best way to learn. The community, myself, and Rob are here to help you along the way, but it’s better done step-by-step.

I hope you understand. :slight_smile:
Brent [import]uid: 200026 topic_id: 34942 reply_id: 139124[/import]

Absolutely… Each level works individually so I planned to just re write it all again anyway and just copy chunks I know work. Then like you said to rework the storyboard part and see what I can figure out. Appreciate all the help to this point. [import]uid: 20272 topic_id: 34942 reply_id: 139268[/import]

You probably should call physics.stop() before changing scenes from level1, if not those functions are going to fire after the scene is moved out of the way.
[import]uid: 199310 topic_id: 34942 reply_id: 138924[/import]

Where should that be added? I tried it at the end of my functions, in my exit scene and at the bottom of the page… i get the same errors and my rocket doesn’t move. [import]uid: 20272 topic_id: 34942 reply_id: 138935[/import]

exitScene() would be a good place. [import]uid: 199310 topic_id: 34942 reply_id: 138937[/import]

Thank you… Right now if I start with main and gotoScene “start”, then click to gotoScene “tutorial” The background loads and scrolls and the missles move but the rocket stays put and get this error.

Copyright © 2009-2012 C o r o n a L a b s I n c .
2013-01-15 06:37:25.323 Corona Simulator[4117:707] Version: 2.0.0
2013-01-15 06:37:25.323 Corona Simulator[4117:707] Build: 2012.971
2013-01-15 06:37:25.324 Corona Simulator[4117:707] The file sandbox for this project is located at the following folder:
(/Users/mkjt88/Library/Application Support/Corona Simulator/Scroller-0925D93CFA3CB11CBDED963F819C3755)
2013-01-15 06:37:39.472 Corona Simulator[4117:707] ERROR: physics.start() has not been called.
2013-01-15 06:37:39.474 Corona Simulator[4117:707] ERROR: physics.start() has not been called.
2013-01-15 06:37:39.475 Corona Simulator[4117:707] ERROR: physics.start() has not been called.

I cannot find a way around it now and I still get my original messages on lvl1 and 2. If I call lvl1 or 2 from main it works fine… but just not if one is played ahead of another. Any ideas? [import]uid: 20272 topic_id: 34942 reply_id: 138986[/import]

Hi @mkjt88,

I glanced at your previous request on this issue last Sunday. While I’d like to solve it for you (and the community would certainly like to help too), it’s somewhat difficult when you provide several hundred lines of code and 3-4 Storyboard scenes in code. Pasting your code certainly helps us solve problems, but too much code requires a “dedicated soul” and a sizable amount of time to really sort through it all, line by line, to figure out what’s going on.

My sincere suggestion is that you roll back your code to just one Storyboard scene with perhaps one or two physics objects. From that, study how Storyboard phases and methods work, and when you should perform various operations and processes. When you stumble upon one problem, focus on solving that first. If it’s still elusive after a due process of problem solving, post to the forums and ask just about that specific issue. Provide only the code related to that, if you can isolate it.

I know it’s frustrating sometimes, but it’s the best way to learn. The community, myself, and Rob are here to help you along the way, but it’s better done step-by-step.

I hope you understand. :slight_smile:
Brent [import]uid: 200026 topic_id: 34942 reply_id: 139124[/import]

Absolutely… Each level works individually so I planned to just re write it all again anyway and just copy chunks I know work. Then like you said to rework the storyboard part and see what I can figure out. Appreciate all the help to this point. [import]uid: 20272 topic_id: 34942 reply_id: 139268[/import]