Hi Rob here’s my level1 code, the goto gameover call is made in the function timesup()
local storyboard = require ("storyboard") local scene = storyboard.newScene() local buttons = require("buttons") local clock = require("clock") local lives = livesRem local pass = Pass local t = 1 local starPos = 0 local m1 = 1 local m2 = 1 local m3 = 1 local m4 = 1 local m5 = 1 local answer = 1 local physics = require("physics") physics.setScale(50) physics.start() function scene:createScene(event) local displayGroup = self.view storyboard.purgeScene( "menu" ) storyboard.purgeScene( "gameOver" ) audio.play( soundTable["backSound"], { channel=5, loops=-1 }) background = display.newImageRect( "images/backdrop.png", 1425, 900 ) background.x = \_W\*0.5; background.y = \_H\*0.5 logo = display.newImageRect("images/gameshow.png", 600, 246) logo.x=\_W\*0.5; logo.y=(\_H\*0.5)\*1.5 displayGroup:insert(background) displayGroup:insert(logo) end function scene:enterScene(event) local group = self.view function showTokens() for i = 1, lives do buttons.livesHeart[i].isVisible= true buttons.livesHeart[i].remove=true end for i = 1, pass do buttons.passToken[i].isVisible= true buttons.passToken[i].remove=true end end function buttons.button1:touch(e) if(e.phase == "ended") and answer == 1 then audio.stop(1) timer.cancel(selftimer) starPos = 1 animateStars() elseif(e.phase == "ended") and answer ~= 1 then audio.stop(1) timer.cancel(selftimer) timesup() end end function buttons.button2:touch(e) if(e.phase == "ended") and answer == 2 then audio.stop(1) timer.cancel(selftimer) starPos = 2 animateStars() elseif(e.phase == "ended") and answer ~= 2 then audio.stop(1) timer.cancel(selftimer) timesup() end end function buttons.button3:touch(e) if(e.phase == "ended") and answer == 3 then audio.stop(1) timer.cancel(selftimer) starPos = 3 animateStars() elseif(e.phase == "ended") and answer ~= 3 then audio.stop(1) timer.cancel(selftimer) timesup() end end function buttons.button4:touch(e) if(e.phase == "ended") and answer == 4 then audio.stop(1) timer.cancel(selftimer) starPos = 4 animateStars() elseif(e.phase == "ended") and answer ~= 4 then audio.stop(1) timer.cancel(selftimer) timesup() end end function questionCount() local options = { text = qCount, x = \_W\*0.183, y = \_H\*0.498, width = 66, height = 66, fontSize = 56, font = "Coaster", align = "center" } questionCountGraphic = display.newText(options) questionCountGraphic:setFillColor( 0.1, 0.1, 0.9 ) questionCountGraphic.isVisible = false questionCountGraphic.remove=true end function buttons.passButton:touch(e) if(e.phase == "ended") and pass \> 0 then buttons.button1:removeEventListener( "touch", buttons.button1 ) buttons.button2:removeEventListener( "touch", buttons.button2 ) buttons.button3:removeEventListener( "touch", buttons.button3 ) buttons.button4:removeEventListener( "touch", buttons.button4 ) buttons.passButton:removeEventListener("touch", buttons.passButton) audio.stop(1) timer.cancel(selftimer) audio.play( soundTable["passSound"], {channel=7} ) transition.to( buttons.passToken[pass], { time=2000, alpha=0, x=\_W\*0.9, y=\_H\*0.5 } ) buttons.passToken[pass].angularVelocity = 50 pass = pass -1 multiplier = 1 multiply() selftimer = timer.performWithDelay(2000, nextQuestion, 1) selftimer.remove=true end end function startTimer() buttons.button1:addEventListener("touch", buttons.button1) buttons.button2:addEventListener("touch", buttons.button2) buttons.button3:addEventListener("touch", buttons.button3) buttons.button4:addEventListener("touch", buttons.button4) buttons.passButton:addEventListener("touch", buttons.passButton) newQuestion() questionCountGraphic.isVisible = true logo.isVisible = false buttons.passButton.isVisible = true t = 1 selftimer = timer.performWithDelay(100, checktime, 61) selftimer.remove=true end function checktime() if t \> 58 then buttons.button1:removeEventListener( "touch", buttons.button1 ) buttons.button2:removeEventListener( "touch", buttons.button2 ) buttons.button3:removeEventListener( "touch", buttons.button3 ) buttons.button4:removeEventListener( "touch", buttons.button4 ) buttons.passButton:removeEventListener("touch", buttons.passButton) end if t == 4 then audio.play( soundTable["ticktock"], {channel=1} ) end if t \<= 60 then local idx = t clock.clocks[idx].isVisible = false idx = idx + 1 clock.clocks[idx].isVisible = true t = idx elseif t == 61 then timesup() end end function nextQuestion() textField1.isVisible = false textField2.isVisible = false textField3.isVisible = false textField4.isVisible = false textField5.isVisible = false questionCountGraphic.isVisible = false audio.stop(1) timer.cancel(selftimer) animateButtons() questionCount() for i = 1, 61 do clock.clocks[i].isVisible = false clock.clocks[i].remove=true end selftimer = timer.performWithDelay(1000, startTimer, 1) end function timesup() buttons.button1:removeEventListener( "touch", buttons.button1 ) buttons.button2:removeEventListener( "touch", buttons.button2 ) buttons.button3:removeEventListener( "touch", buttons.button3 ) buttons.button4:removeEventListener( "touch", buttons.button4 ) buttons.passButton:removeEventListener("touch", buttons.passButton) audio.play( soundTable["wrongSound"], {channel=3} ) lives = lives -1 multiplier = 1 multiply() if lives == -1 then transition.cancel() timer.cancel( selftimer ) storyboard.gotoScene("gameOver", {time=1000, effect = "crossFade"}) elseif lives \>= 0 then transition.to( buttons.livesHeart[lives+1], { time=2000, alpha=0, x=\_W\*0.92, y=\_H\*0.82 } ) buttons.livesHeart[lives+1].angularVelocity = 50 end selftimer = timer.performWithDelay(2000, nextQuestion, 1) end function updateScore() if t \< 62 then idx = t clock.clocks[idx].isVisible = false scGraphic.isVisible = false scoreGraphic() idx = idx + 1 clock.clocks[idx].isVisible = true t = idx audio.play( soundTable["chinkSound"] ) end end function animateStars() buttons.button1:removeEventListener( "touch", buttons.button1 ) buttons.button2:removeEventListener( "touch", buttons.button2 ) buttons.button3:removeEventListener( "touch", buttons.button3 ) buttons.button4:removeEventListener( "touch", buttons.button4 ) buttons.passButton:removeEventListener("touch", buttons.passButton) audio.play( soundTable["correctSound"], {channel=2} ) if multiplier \< 5 then multiplier = multiplier + 1 end multiply() local star = {} star[1] = display.newImageRect("images/star.png", 140, 140) star[2] = display.newImageRect("images/star1.png", 140, 140) star[3] = display.newImageRect("images/star2.png", 140, 140) star[4] = display.newImageRect("images/star.png", 140, 140) star[5] = display.newImageRect("images/star1.png", 140, 140) star[6] = display.newImageRect("images/star2.png", 140, 140) star[7] = display.newImageRect("images/star1.png", 140, 140) star[8] = display.newImageRect("images/star2.png", 140, 140) star[9] = display.newImageRect("images/star.png", 140, 140) star[10] = display.newImageRect("images/star1.png", 140, 140) local i = 1 repeat if starPos == 1 then star[i].x = \_W\*0.36; x=star[i].x; star[i].y = \_H\*0.73; y=star[i].y end if starPos == 2 then star[i].x =\_W\*0.7; x=star[i].x; star[i].y = \_H\*0.73; y=star[i].y end if starPos == 3 then star[i].x = \_W\*0.36; x=star[i].x; star[i].y = \_H\*0.9; y=star[i].y end if starPos == 4 then star[i].x = \_W\*0.7; x=star[i].x; star[i].y = \_H\*0.9; y=star[i].y end star[i].anchorX=0.5; star[i].anchorY=0.5 physics.addBody( star[i], "dynamic", {density=0.5, friction=0.1, radius=35} ) star[i].remove=true i = i +1 until i == 11 transition.to( star[1], { time=2000, alpha=0, x=x-200, y=y-200 } ) star[1].angularVelocity = 50 transition.to( star[2], { time=1500, alpha=0, 0, y=y-200 } ) star[2].angularVelocity = 70 transition.to( star[3], { time=2000, alpha=0, x=x+200, y=y-200 } ) star[3].angularVelocity = -50 transition.to( star[4], { time=1500, alpha=0, x=x+100, y=y-100 } ) star[4].angularVelocity = 40 transition.to( star[5], { time=2000, alpha=0, x=x-200, y=y-100 } ) star[5].angularVelocity = -60 transition.to( star[6], { time=1500, alpha=0, x=x+100, y=y+100 } ) star[6].angularVelocity = 50 transition.to( star[8], { time=2000, alpha=0, x=x+200, 0 } ) star[8].angularVelocity = -50 transition.to( star[9], { time=1500, alpha=0, x=x-100, y=y+100 } ) star[9].angularVelocity = 60 transition.to( star[10], { time=2000, alpha=0, x=x-200, 0 } ) star[10].angularVelocity = -60 selftimer = timer.performWithDelay(20, updateScore, (61-t)) selftimer = timer.performWithDelay(2000, nextQuestion, 1) end function animateButtons() buttons.passButton.isVisible = false questionCountGraphic.isVisible = false logo.isVisible = true audio.stop(1) audio.play( soundTable["whooshSound"], {channel=6} ) transition.moveTo( buttons.button1, { x=\_W+400, y=\_H\*0.73, time=500 } ) transition.moveTo( buttons.button2, { x=\_W+400, y=\_H\*0.73, time=500 } ) transition.moveTo( buttons.button3, { x=\_W+400, y=\_H\*0.9, time=500 } ) transition.moveTo( buttons.button4, { x=\_W+400, y=\_H\*0.9, time=500 } ) transition.moveTo( buttons.button5, { x=\_W+1000, y=\_H\*0.5, time=500 } ) selftimer = timer.performWithDelay(500, animateButtons1, 1) end function animateButtons1() transition.moveTo( buttons.button1, { x=\_W\*0.36, y=\_H\*0.73, time=500 } ) transition.moveTo( buttons.button2, { x=\_W\*0.7, y=\_H\*0.73, time=500 } ) transition.moveTo( buttons.button3, { x=\_W\*0.36, y=\_H\*0.9, time=500 } ) transition.moveTo( buttons.button4, { x=\_W\*0.7, y=\_H\*0.9, time=500 } ) transition.moveTo( buttons.button5, { x=\_W\*0.5, y=\_H\*0.5, time=500 } ) end function scoreGraphic() score = score + (multiplier\*10) local options = { text = score, x = \_W\*0.87, y = \_H\*0.19, width = 200, height = 100, fontSize = 64, font = "Coaster", align = "right" } scGraphic = display.newText(options) scGraphic:setFillColor( 0, 0.3, 0.9 ) scGraphic.remove=true end function multiply() if m1 == 3 then m1 = 1 elseif m1 == 1 then direction1 = -360 else direction1 = 360 end if m2 == 3 then m2 = 1 elseif m2 == 1 then direction2 = -360 else direction2 = 360 end if m3 == 3 then m3 = 1 elseif m3 == 1 then direction3 = -360 else direction3 = 360 end if m4 == 3 then m4 = 1 elseif m4 == 1 then direction4 = -360 else direction4 = 360 end if m5 == 3 then m5 = 1 elseif m5 == 1 then direction5 = -360 else direction5 = 360 end buttons.multiply1.isVisible = false buttons.multiply2.isVisible = false buttons.multiply3.isVisible = false buttons.multiply4.isVisible = false buttons.multiply5.isVisible = false if multiplier == 1 then m1=m1+1 buttons.multiply1.isVisible = true buttons.multiply1.anchorX=0.5; buttons.multiply1.anchorY=0.5 transition.to( buttons.multiply1, { rotation=direction1, time=3000, transition=easing.inOutCubic } ) end if multiplier == 2 then m2=m2+1 buttons.multiply2.isVisible = true buttons.multiply2.anchorX=0.5; buttons.multiply2.anchorY=0.5 transition.to( buttons.multiply2, { rotation=direction2, time=3000, transition=easing.inOutCubic } ) end if multiplier == 3 then m3=m3+1 buttons.multiply3.isVisible = true buttons.multiply3.anchorX=0.5; buttons.multiply3.anchorY=0.5 transition.to( buttons.multiply3, { rotation=direction3, time=3000, transition=easing.inOutCubic } ) end if multiplier == 4 then m4=m4+1 buttons.multiply4.isVisible = true buttons.multiply4.anchorX=0.5; buttons.multiply4.anchorY=0.5 transition.to( buttons.multiply4, { rotation=direction4, time=3000, transition=easing.inOutCubic } ) end if multiplier == 5 then m5=m5+1 buttons.multiply5.isVisible = true buttons.multiply5.anchorX=0.5; buttons.multiply5.anchorY=0.5 transition.to( buttons.multiply5, { rotation=direction5, time=3000, transition=easing.inOutCubic } ) end end function newQuestion() repeat r = math.random(questions.c-1) for i = 1, qCount do if questionsAsked[i] == r then r = 0 end end until r ~= 0 questionsAsked[qCount] = r qCount = qCount + 1 question = (questions.question[r]) answer\_1 = (questions.ans\_1[r]) answer\_2 = (questions.ans\_2[r]) answer\_3 = (questions.ans\_3[r]) answer\_4 = (questions.ans\_4[r]) for i = 1, 4 do local ran = math.random(4) if ran == 1 then local a = answer\_1; answer\_1 = answer\_2; answer\_2 = a end if ran == 2 then local a = answer\_2; answer\_2 = answer\_3; answer\_3 = a end if ran == 3 then local a = answer\_3; answer\_3 = answer\_4; answer\_4 = a end if ran == 4 then local a = answer\_4; answer\_4 = answer\_1; answer\_1 = a end end k=0 for j = 1, string.len(answer\_1) do local a=string.sub(answer\_1, j, j ) if a == "\*" then k=j end end if k ~= 0 then answer=1; answer\_1 = string.sub(answer\_1, 1, k-2 ) end k=0 for j = 1, string.len(answer\_2) do local a=string.sub(answer\_2, j, j ) if a == "\*" then k=j end end if k ~= 0 then answer=2; answer\_2 = string.sub(answer\_2, 1, k-2 ) end k=0 for j = 1, string.len(answer\_3) do local a=string.sub(answer\_3, j, j ) if a == "\*" then k=j end end if k ~= 0 then answer=3; answer\_3 = string.sub(answer\_3, 1, k-2 ) end k=0 for j = 1, string.len(answer\_4) do local a=string.sub(answer\_4, j, j ) if a == "\*" then k=j end end if k ~= 0 then answer=4; answer\_4 = string.sub(answer\_4, 1, k-2 ) end if string.len(answer\_1) \< 19 then ts1 = 48; yht1=1.03 elseif string.len(answer\_1) \> 18 then ts1 = 38; yht1=1.04 end if string.len(answer\_2) \< 19 then ts2 = 48; yht2=1.03 elseif string.len(answer\_2) \> 18 then ts2 = 38; yht2=1.04 end if string.len(answer\_3) \< 19 then ts3 = 48; yht3=1.03 elseif string.len(answer\_3) \> 18 then ts3 = 38; yht3=1.04 end if string.len(answer\_4) \< 19 then ts4 = 48; yht4=1.03 elseif string.len(answer\_4) \> 18 then ts4 = 38; yht4=1.04 end if string.len(question) \<= 35 then ht=1.15 elseif string.len(question) \> 35 then ht=1.1 end local myText = question local options = { text = myText, x = \_W\*0.54, y =(\_H\*0.5)\*ht, width = 800, height = 200, fontSize = 50, font = "Coaster", align = "center" } textField1 = display.newText( options ) textField1:setFillColor( 0, 0.3, 0.9 ) textField1.remove=true local myText = answer\_1 local options = { text = myText, x = \_W\*0.36, y = (\_H\*0.73)\*yht1, width = 580, height = 100, fontSize = ts1, font = "Coaster", align = "center" } textField2 = display.newText( options ) textField2:setFillColor( 0, 0.3, 0.9 ) textField2.remove=true local myText = answer\_2 local options = { text = myText, x = \_W\*0.7, y = (\_H\*0.73)\*yht2, width = 580, height = 100, fontSize = ts2, font = "Coaster", align = "center" } textField3 = display.newText( options ) textField3:setFillColor( 0, 0.3, 0.9 ) textField3.remove=true local myText = answer\_3 local options = { text = myText, x = \_W\*0.36, y = (\_H\*0.9)\*yht3, width = 580, height = 100, fontSize = ts3, font = "Coaster", align = "center" } textField4 = display.newText( options ) textField4:setFillColor( 0, 0.3, 0.9 ) textField4.remove=true local myText = answer\_4 local options = { text = myText, x = \_W\*0.7, y = (\_H\*0.9)\*yht4, width = 580, height = 100, fontSize = ts4, font = "Coaster", align = "center" } textField5 = display.newText( options ) textField5:setFillColor( 0, 0.3, 0.9 ) textField5.remove=true end showTokens() multiply() scoreGraphic() questionCount() startTimer() end function scene:exitScene(event) local group = self.view audio.stop(5) timer.cancel(selftimer) self.timer = nil if physics then physics.stop() end textField1.isVisible=false textField2.isVisible=false textField3.isVisible=false textField4.isVisible=false textField5.isVisible=false buttons.multiply5.isVisible = false buttons.multiply4.isVisible = false buttons.multiply3.isVisible = false buttons.multiply2.isVisible = false buttons.multiply1.isVisible = false buttons.scoreCard.isVisible = false buttons.livesCard.isVisible = false buttons.passCard.isVisible = false scGraphic.isVisible = false buttons.button1.isVisible = false buttons.button2.isVisible = false buttons.button3.isVisible = false buttons.button4.isVisible = false buttons.button5.isVisible = false buttons.passButton.isVisible = false questionCountGraphic.isVisible = false for i = 1, 61 do clocks[i].isVisible = false end for i=1, 5 do buttons.livesHeart[i].isVisible = false buttons.passToken[i].isVisible = false end buttons.button1:removeEventListener( "touch", buttons.button1 ) buttons.button2:removeEventListener( "touch", buttons.button2 ) buttons.button3:removeEventListener( "touch", buttons.button3 ) buttons.button4:removeEventListener( "touch", buttons.button4 ) buttons.passButton:removeEventListener("touch", buttons.passButton) buttons.multiply1.remove=true buttons.multiply2.remove=true buttons.multiply3.remove=true buttons.multiply4.remove=true buttons.multiply5.remove=true collectgarbage( "collect" ) end function scene:destroyScene(event) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
Here’s the gameover code…
local storyboard = require ("storyboard") local scene = storyboard.newScene() storyboard.purgeScene( "level1" ) storyboard.removeScene( "level1" ) storyboard.purgeScene( "menu" ) local background, logo, replayButton, statsButton function scene:createScene(event) local group = self.view audio.play( soundTable["menuSound"], { channel=7, loops=-1 }) background = display.newImageRect( "images/backdrop.png", 1425, 900 ) background.x = \_W\*0.5; background.y = \_H\*0.5 logo = display.newImageRect("images/gameshow.png", 600, 246) logo.x=\_W\*0.5; logo.y=(\_H\*0.5)\*1.5 replayButton = display.newImageRect("images/Replaybutton.png", 300, 87) replayButton.x=\_W\*0.3; replayButton.y=\_H\*0.25 statsButton = display.newImageRect("images/Statsbutton.png", 300, 87) statsButton.x=\_W\*0.7; statsButton.y=\_H\*0.25 group:insert(background) group:insert(logo) group:insert(statsButton) group:insert(replayButton) end function scene:enterScene(event) local group = self.view function play(e) if e.phase == "ended" then storyboard.gotoScene("level1", {time=1000, effect = "slideRight"}) end end function stats(e) if e.phase == "ended" then storyboard.gotoScene("menu", {time=1000, effect = "slideRight"}) end end replayButton:addEventListener("touch", play) statsButton:addEventListener("touch", stats) end function scene:exitScene(event) local group = self.view audio.stop(7) replayButton:removeEventListener("touch", play) statsButton:removeEventListener("touch", stats) end function scene:destroyScene(event) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
It’s a lot, sorry.