hi, I am building my very first app and I believe I am this one error away from finishing and being able to publish the app.
the app should run like this:
runs main.lua - main.lua tells the app to go to “view1.lua”
view1.lua is the main menu which has a single “play” button, the play button makes the app go to “view2.lua”
view2.lua is the main game, there is a timer counting down and when it hits 0 it loads “view3.lua” which is the “game over screen”
in view3 there is a play again button which reloads and re-initialises view2.lua
then it’s just back and forth between view2 and view3 until the user quits
my problem is it only does that once… so the game runs twice before it crashes.
the stack trace is this:
…)(builds)\bubbleer(2)(default)\bubbleer(2)\view2.lua:114: attempt to call method ‘removeSelf’ (a nil value)
message
stack traceback:
?: in function <?:218>
[C]: in function ‘removeSelf’
…)(builds)\bubbleer(2)(default)\bubbleer(2)\view2.lua:114: in function ‘_listener’
?: in function <?:141>
?: in function <?:218>
----------------------------------------------------------------------------------------- -- -- view2.lua -- ----------------------------------------------------------------------------------------- print("miltitouch activated") system.activate( "multitouch" ) print("declerations") local storyboard = require( "storyboard" ) local scene = storyboard.newScene() storyboard.disableAutoPurge = false local pop = audio.loadStream('pop.mp3') local unPop = audio.loadStream('unpop.mp3') --local loading = audio.loadStream('load.mp3') local bubble = {} local timed local score local group local Dscore local Dtime ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- local Dscore ----------------------------------------------------------------------------------------- print("implementations") -- Called when the scene's view does not exist: function scene:createScene( event ) print("scene:createScene") group = self.view print("group = self.view") init() ------------------------------------------------------------------------------------------- end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) --local group = self.view print("enterScene") -- do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view print("ExitScene") -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) print("ERROR: DESTROYING SCENE") -- Dscore = null --Dtime = null --scene:removeSelf() -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end function bubbleTap( event ) if timed \>0 then print("popping") local oldBubble = event.target local count = oldBubble.index audio.rewind(pop) audio.play(pop) bubble[count] = display.newImage( 'bubbleDown.png' ) bubble[count].x = oldBubble.x bubble[count].y = oldBubble.y bubble[count].index = count --bubble[Count]:addEventListener("tap", bubbleTap) scene.view:insert(bubble[count]) updateScore() oldBubble:removeSelf() if timed \> 1 then timer.performWithDelay(1500, function() bubbleUnPop(bubble[count]) end) end end end function bubbleUnPop( event ) print("unpopping") local oldBubble = event print("bubble"..oldBubble.index) local count = oldBubble.index audio.rewind(unPop) audio.play(unPop) bubble[count] = display.newImage( 'bubble.png' ) bubble[count].x = oldBubble.x bubble[count].y = oldBubble.y bubble[count].index = count timer.performWithDelay( 100, function() bubble[count]:addEventListener("tap", bubbleTap) end, 1) scene.view:insert(bubble[count]) oldBubble:removeSelf() end function countdown () print("counting down - at: "..timed) print("using clock: ") print(Dtime) if timed == 0 then gameEnd() else timed = timed -1 Dtime:removeSelf() Dtime = display.newText("Time: ".. timed, 0, 0, native.systemFont, 14) Dtime.x = display.contentWidth -30 end end function updateScore() score = score+1 Dscore:removeSelf() Dscore = display.newText("Score: ".. score, 0, 0, native.systemFont, 14) end function gameEnd( event ) Dscore:removeSelf() Dtime:removeSelf() print("------------------------------------------------------------------------stats-------------------------------------------------------") print(Dscore) print(Dtime) print("-------------------------------------------------------------------------------------------------------------------------------") timer.performWithDelay(100, function() storyboard.gotoScene( "view3", {params = {scored = score}}) end) end function init() print("initialising....") print(Dscore) score = 0 timed = 6 -- create a white background to fill screen print("creating background") local bg = display.newImage('bgG.png' ) print("creating UIBar") local titleBar = display.newRect(0,0,display.contentWidth,20) titleBar:setFillColor(75,0,0) --create the score print("creating Dscore with score of: "..score) Dscore = display.newText("Score: ".. score, 0, 0, native.systemFont, 14) --create the time print("creating Dtime with time of: "..timed) Dtime = display.newText("Time: ".. timed, 0, 0, native.systemFont, 14) Dtime.x = display.contentWidth -30 -- all objects must be added to group (e.g. self.view) group:insert( bg ) print("background inserted") group:insert( titleBar ) print("UI inserted") group:insert( Dtime ) print("Dtime inserted") group:insert( Dscore ) print("Dscore inserted") -------------------------------create the bubbles------------------------------------------ local count = 1 --audio.rewind(load) --audio.play(load) for i=9,display.contentWidth,19 do--bubble horizontal for j=30,display.contentHeight,19 do--bubble verticle print("creating new bubble"..count) bubble[count] = display.newImage('bubble.png' ) bubble[count].index = count bubble[count].x = i bubble[count].y = j group:insert( bubble[count] ) bubble[count]:addEventListener("tap", bubbleTap) count = count+1 end end end function reInit() print("reinitialising...") -- storyboard.reloadScene() init() end timer.performWithDelay(1000, countdown, 7) ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
----------------------------------------------------------------------------------------- -- -- view3.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local widget = require( "widget" ) local scene = storyboard.newScene() local scores = {} local i = 1 ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) -- local group = self.view -- local score = event.params.scored -- -- create a white background to fill screen -- local bg = display.newImage('bg.png' ) -- -- -- create some text -- local title = display.newText( "Time Up", 0, 0, native.systemFont, 32 ) -- title:setTextColor( 0 ) -- black -- title:setReferencePoint( display.CenterReferencePoint ) -- title.x = display.contentWidth \* 0.5 -- title.y = 125 -- -- local summary = display.newText("score: ".. score, 0, 0, 300, 300, native.systemFont, 14 ) -- summary:setTextColor( 0 ) -- black -- summary:setReferencePoint( display.CenterReferencePoint ) -- summary.x = display.contentWidth \* 0.5 + 10 -- summary.y = title.y + 215 -- -- -- --local hScore = widget.newTableView{ -- --width = 108, -- --height = 160, -- --mask = "hScore.png" -- --} -- ---- hScore:insertRow{ ---- id = "score-".. i, ---- onRender = onRowRender ---- } ---- hScore.x = display.contentWidth/3 ---- hScore.y = display.contentHeight - 190 -- --createHighScore() -- local play = display.newImage('playA.png') -- play.x = display.contentWidth/2 -- play.y = display.contentWidth/2 -- timer.performWithDelay(100, function() play:addEventListener( "tap", Play) end, 1) -- -- all objects must be added to group (e.g. self.view) -- group:insert( bg ) -- group:insert( title ) -- group:insert( summary ) -- group:insert( play ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view local score = event.params.scored -- create a white background to fill screen local bg = display.newImage('bg.png' ) -- create some text local title = display.newText( "Time Up", 0, 0, native.systemFont, 32 ) title:setTextColor( 0 ) -- black title:setReferencePoint( display.CenterReferencePoint ) title.x = display.contentWidth \* 0.5 title.y = 125 local summary = display.newText("score: ".. score, 0, 0, 300, 300, native.systemFont, 14 ) summary:setTextColor( 0 ) -- black summary:setReferencePoint( display.CenterReferencePoint ) summary.x = display.contentWidth \* 0.5 + 10 summary.y = title.y + 215 ----------------------------------------------------------memo to self to learn how to create High score table for local user------------------------ --local hScore = widget.newTableView{ --width = 108, --height = 160, --mask = "hScore.png" --} -- hScore:insertRow{ -- id = "score-".. i, -- onRender = onRowRender -- } -- hScore.x = display.contentWidth/3 -- hScore.y = display.contentHeight - 190 --createHighScore() local play = display.newImage('playA.png') play.x = display.contentWidth/2 play.y = display.contentWidth/2 timer.performWithDelay(100, function() play:addEventListener( "tap", Play) end, 1) -- all objects must be added to group (e.g. self.view) group:insert( bg ) group:insert( title ) group:insert( summary ) group:insert( play ) -- do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end function Play() --reInit() storyboard.removeScene("view2") storyboard.gotoScene( "view2" ) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
can anybody help me with this issue? I have spent the last day or so working on it