Composer appears to not be working (Unable to use gotoScene)

Hello,

I seem to be having a problem with my game scene in that it does not seem to use composer i.e. I set up a back button that returns to the “start” page but it appears to not work.

Here is the code

local sceneName = ... local composer = require( "composer" ) local physics = require("physics") local widget = require("widget") local scene = composer.newScene(sceneName) ----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view display.setStatusBar(display.HiddenStatusBar) screenWidth = display.contentWidth screenHeight = display.contentHeight local background = display.newImageRect( "background.png", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY physics.start(true) physics.setGravity(0,50); local theWord = "" -- the word the user spells local theWordText -- shows the word the user writes local isNewGame local allBallsGroup -- group to hold all the balls local wordTable = {} -- will hold the words from the text file local chosenBalls = {} -- holds the balls the user has chosen local instructionsText -- shows instructions local gameOverText -- shows game over local countDownText -- shows the time local numBallsToGenerate = 10 -- how many balls to generate local allBalls = {} -- holds all the balls that have been generated local theBombs = {} -- holds references to the bomb image local generateBallTimer -- timer for generating balls local clockTimer -- timer for the clock local gameTime = 20 -- how many seconds before new balls drop function Setup() &nbsp;&nbsp; &nbsp;math.randomseed(os.time()) &nbsp;&nbsp; &nbsp;--gameOverText.text="" &nbsp;&nbsp; &nbsp;SetupGameAssets() &nbsp;&nbsp; &nbsp;StartButton() &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;--gameOverText.text = nil &nbsp;&nbsp; &nbsp; end function StartButton() &nbsp;&nbsp; &nbsp;startButton = widget.newButton({ &nbsp;&nbsp; &nbsp;label = "START", &nbsp;&nbsp; &nbsp;labelColor = { default={ 0.1,0.5,0.2 }, over={ 0.1,0.5,0.2, 0.7 }}, &nbsp;&nbsp; &nbsp;fontSize = 25, &nbsp;&nbsp; &nbsp;onRelease = StartButtonPress, &nbsp;&nbsp; &nbsp;shape = "circle", &nbsp;&nbsp; &nbsp;width = 200, &nbsp;&nbsp; &nbsp;height = 40, &nbsp;&nbsp; &nbsp;cornerRadius = 2, &nbsp;&nbsp; &nbsp;radius = 60, &nbsp;&nbsp; &nbsp;fillColor = {default={0.6,1,0.7,0}, over={0.6,1,0.7,0}}, &nbsp;&nbsp; &nbsp;strokeColor = {default ={0.1,0.5,0.2,0.7}, over={0.1,0.5,0.2,0.5}}, &nbsp;&nbsp; &nbsp;strokeWidth = 8}) &nbsp;&nbsp; &nbsp;startButton.x = display.contentCenterX &nbsp;&nbsp; &nbsp;startButton.y = 200 &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;returnMenuButton = widget.newButton({ &nbsp;&nbsp; &nbsp;label = "Back to Menu", &nbsp;&nbsp; &nbsp;labelColor = { default={ 0.1,0,0.5 }, over={ 0.1,0,0.5, 0.7 }}, &nbsp;&nbsp; &nbsp;fontSize = 20, &nbsp;&nbsp; &nbsp;onRelease = MenuButtonPress, &nbsp;&nbsp; &nbsp;shape = "roundedRect", &nbsp;&nbsp; &nbsp;width = 160, &nbsp;&nbsp; &nbsp;height = 40, &nbsp;&nbsp; &nbsp;cornerRadius = 2, &nbsp;&nbsp; &nbsp;fillColor = {default={0.6,1,0.7,0}, over={0.6,1,0.7,0}}, &nbsp;&nbsp; &nbsp;strokeColor = {default ={0.1,0,0.5,0.7}, over={0.1,0,0.5,0.5}}, &nbsp;&nbsp; &nbsp;strokeWidth = 8}) &nbsp;&nbsp; &nbsp;returnMenuButton.x = display.contentCenterX &nbsp;&nbsp; &nbsp;returnMenuButton.y = 340 &nbsp;&nbsp; &nbsp;--gameOverText:removeSelf() end&nbsp;&nbsp; &nbsp; -- show() back button function backButton() &nbsp;&nbsp; &nbsp;backbutton = widget.newButton( &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{ &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 45, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 45, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onEvent = backbuttonEvent1, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; emboss = false, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;defaultFile = "arrow.png", &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;overFile = "arrowover.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} &nbsp;&nbsp; &nbsp;) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;--back button bottom left &nbsp;&nbsp; &nbsp;backbutton.x = display.contentCenterX\*1.8 &nbsp;&nbsp; &nbsp;backbutton.y = display.contentCenterY\*0.13 end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; function StartButtonPress(event) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;startButton.isVisible = false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;returnMenuButton.isVisible = false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;gameOverText.text = "" &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;NewGame() end function returnMenuButton( event ) &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( "ended" == event.phase ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;composer.gotoScene("start") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; -- back button function local function backbuttonEvent1( event ) &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( "ended" == event.phase ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;composer.gotoScene("start") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; function NewGame() &nbsp;&nbsp; &nbsp;isNewGame = true &nbsp;&nbsp; &nbsp;chosenBalls = {} &nbsp;&nbsp; &nbsp;allBalls = {} &nbsp;&nbsp; &nbsp;theWord = "" &nbsp;&nbsp; &nbsp;theWordText.text = "" &nbsp;&nbsp; &nbsp;instructionsText.text = "" &nbsp;&nbsp; &nbsp;gameOverText.text = "" &nbsp;&nbsp; &nbsp;countDownText.text = gameTime; &nbsp;&nbsp; &nbsp;CreateVowelBalls(2) &nbsp;&nbsp; &nbsp;CreateSpecialChar(2) &nbsp;&nbsp; &nbsp;GenerateBalls() &nbsp;&nbsp;&nbsp; StartTimer() &nbsp;&nbsp;&nbsp; isNewGame = false &nbsp;&nbsp;&nbsp; SetBombsVisible(); &nbsp;&nbsp;&nbsp; gameOverText.isVisible = false; &nbsp;&nbsp; &nbsp;backButton() end function SetupGameBoundaries() &nbsp;&nbsp; &nbsp;local groundLine = display.newRect(0, 430,display.contentWidth+330, 2); &nbsp;&nbsp; &nbsp;local lineLeft = display.newRect(-0,0,2,display.contentHeight+400); &nbsp;&nbsp; &nbsp;local lineRight = display.newRect(display.contentWidth,0,2,display.contentHeight+400) &nbsp;&nbsp; &nbsp;physics.addBody(groundLine, 'static',{bounce=0,friction=0}) &nbsp;&nbsp; &nbsp;physics.addBody(lineLeft, 'static',{bounce=0,friction=0}); &nbsp;&nbsp; &nbsp;physics.addBody(lineRight,'static',{bounce=0,friction=0}); &nbsp;&nbsp; &nbsp;groundLine.isVisible = false; &nbsp;&nbsp; &nbsp;lineLeft.isVisible = false; &nbsp;&nbsp; &nbsp;lineRight.isVisible = false;&nbsp;&nbsp; &nbsp; end function SetupButtons() &nbsp;&nbsp; &nbsp;local goButton = display.newImage("goButton.png",280,465); &nbsp;&nbsp; &nbsp;goButton:addEventListener('tap', CheckWord); &nbsp;&nbsp; &nbsp;local stopButton = display.newImage("stopButton.png",30,465); &nbsp;&nbsp; &nbsp;stopButton:addEventListener('tap',ResetWord) &nbsp;&nbsp; &nbsp;local bar = display.newImage("bar.png",0,100) &nbsp;&nbsp; &nbsp;bar.x = display.contentCenterX &nbsp;&nbsp; &nbsp;bar.y = display.contentHeight-400 &nbsp;&nbsp; &nbsp; end function SetupTextFields() &nbsp;&nbsp; &nbsp;countDownText = display.newText(gameTime,290,5,native.systemFontBold,20); &nbsp;&nbsp; &nbsp;countDownText:setTextColor("#000000"); &nbsp;&nbsp; &nbsp;theWordText = display.newText("",60,470,native.systemFontBold,25); &nbsp;&nbsp; &nbsp;theWordText:setTextColor("#000000"); &nbsp;&nbsp; &nbsp;instructionsText = display.newText("",0,0,native.systemFontBold,25); &nbsp;&nbsp; &nbsp;instructionsText.x = display.contentWidth/2; &nbsp;&nbsp; &nbsp;instructionsText.y = display.contentHeight/10; &nbsp;&nbsp; &nbsp;instructionsText:setTextColor("19007f"); end function SetupGameOverField() &nbsp;&nbsp; &nbsp;gameOverText = display.newText("",0,0,native.systemFontBold,25); &nbsp;&nbsp; &nbsp;gameOverText.x = display.contentCenterX; &nbsp;&nbsp; &nbsp;gameOverText.y = display.contentCenterY; &nbsp;&nbsp; &nbsp;gameOverText:setTextColor("19007f"); &nbsp;&nbsp; &nbsp;gameOverText.isVisible = false; end function SetupGameAssets() &nbsp;&nbsp; &nbsp;ReadTextFile() &nbsp;&nbsp; &nbsp;SetupGameBoundaries() &nbsp;&nbsp; &nbsp;SetupButtons() &nbsp;&nbsp; &nbsp;SetupTextFields() &nbsp;&nbsp; &nbsp;SetupGameOverField() &nbsp;&nbsp; &nbsp;SetupBombs() &nbsp;&nbsp; &nbsp;allBallsGroup = display.newGroup(); end function SetupBombs() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i=1, 5 do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; local tempBomb = display.newImage("bomb.png") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tempBomb.width = 30 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tempBomb.height = 30 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tempBomb.x =&nbsp; 33 \* i &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tempBomb.y = 0 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; tempBomb:addEventListener('tap', Explode) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; table.insert(theBombs,tempBomb) &nbsp;&nbsp; &nbsp;end end function SetBombsVisible() &nbsp;&nbsp; &nbsp;for i=1, #theBombs do &nbsp;&nbsp; &nbsp;theBombs[i].isVisible = true; &nbsp;&nbsp; &nbsp;end end function SetBombsInvisible() &nbsp;&nbsp; &nbsp;for i=1, #theBombs do &nbsp;&nbsp; &nbsp;theBombs[i].isVisible = false; &nbsp;&nbsp; &nbsp;end end function GenerateBalls() &nbsp;&nbsp; &nbsp;timer.performWithDelay(1500,CheckGameOver) &nbsp;&nbsp; &nbsp;if(isNewGame == true) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;numBallsToGenerate = 10 &nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;numBallsToGenerate = 4 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CreateVowelBalls(1) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--CreateSpecialChar(1) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;generateBallTimer = timer.performWithDelay( 50, CreateBall, numBallsToGenerate) end function StartTimer() &nbsp;&nbsp; &nbsp;clockTimer = timer.performWithDelay(1000,DoCountdown,gameTime) end function DoCountdown() &nbsp;&nbsp; &nbsp;local currentTime = countDownText.text &nbsp;&nbsp; &nbsp;currentTime = currentTime -1 &nbsp;&nbsp; &nbsp;countDownText.text = currentTime &nbsp;&nbsp; &nbsp; if(currentTime == 0) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;GenerateBalls() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;countDownText.text = gameTime &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;StartTimer() &nbsp;&nbsp; &nbsp;end end &nbsp;&nbsp; &nbsp; function CreateBall(createVowel) -- creates one ball. Takes one argument, the letter the ball contains &nbsp;&nbsp; &nbsp;local var alphabetArray = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} &nbsp;&nbsp; &nbsp;local vowels = {"A", "E", "I", "O", "U",} &nbsp;&nbsp; &nbsp;local specialChar = {"Á", "É", "Í", "Ó", "Ú", "Ñ"} &nbsp;&nbsp; &nbsp;local ballType = math.random(4) &nbsp;&nbsp; &nbsp;local ballSize = math.random(2) &nbsp;&nbsp; &nbsp;local letterIndex &nbsp;&nbsp; &nbsp;local letter &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(createVowel == true) then &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letterIndex = math.random(#vowels) &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letter = vowels[letterIndex] &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letterIndex = math.random(#specialChar); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letter = specialChar[letterIndex] &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letterIndex = math.random(#alphabetArray) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; letter = alphabetArray[letterIndex]&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp; &nbsp;local ballGroup = display.newGroup(); &nbsp;&nbsp; &nbsp;local ball &nbsp;&nbsp; &nbsp;local ballRadius &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(ballType == 1) then &nbsp;&nbsp; &nbsp;&nbsp; ball = display.newImage("greenBall.png") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elseif(ballType == 2) then &nbsp;&nbsp; &nbsp;&nbsp; ball = display.newImage("brownBall.png") &nbsp;&nbsp; &nbsp;&nbsp; elseif(ballType == 3) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ball = display.newImage("pinkBall.png") &nbsp;&nbsp; &nbsp;&nbsp; else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ball = display.newImage("redBall.png") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(ballSize == 1)then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ball.width&nbsp; = 48 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ball.height = 48 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ballRadius = 24 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ball.width = 58 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ball.height = 58 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ballRadius = 29 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp; &nbsp;&nbsp; &nbsp;local letterText = display.newText( letter, 0,0, native.systemFontBold, 25 ); &nbsp;&nbsp; &nbsp;letterText:setTextColor(0,0, 0) &nbsp;&nbsp; &nbsp;letterText.x = ball.x &nbsp;&nbsp; &nbsp;letterText.y = ball.y &nbsp;&nbsp; &nbsp;ballGroup:insert(ball) &nbsp;&nbsp; &nbsp;ballGroup:insert(letterText) &nbsp;&nbsp; &nbsp;ballGroup.x = math.random(ballRadius,display.contentWidth-ballRadius\*2) &nbsp;&nbsp; &nbsp;ballGroup.y= - 40 &nbsp;&nbsp; &nbsp;physics.addBody(ballGroup, 'dynamic',{friction = 0,bounce = 0,radius = ballRadius}) &nbsp;&nbsp; &nbsp;ballGroup.name = "ball" &nbsp;&nbsp; &nbsp;ballGroup.letter = letter &nbsp;&nbsp; &nbsp;ballGroup:addEventListener('tap',FormString) &nbsp;&nbsp; &nbsp;table.insert(allBalls,ballGroup) &nbsp;&nbsp; &nbsp;allBallsGroup:insert(ballGroup) end function CheckGameOver () &nbsp;&nbsp; &nbsp;local gameOver = false; &nbsp;&nbsp; &nbsp;for i=1,#allBalls do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if(allBalls[i].y \< (100 - allBalls[i].height))then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gameOver = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;if(gameOver) then &nbsp;&nbsp; &nbsp;for i=allBallsGroup.numChildren,1,-1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local child = allBallsGroup[i] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; child:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; child = nil; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;timer.cancel(generateBallTimer) &nbsp;&nbsp; &nbsp;timer.cancel(clockTimer) &nbsp;&nbsp; &nbsp;SetupGameOverField() &nbsp;&nbsp; &nbsp;gameOverText.text = "Game Over"; &nbsp;&nbsp; &nbsp;--gameOverText:toFront() &nbsp;&nbsp; &nbsp;SetBombsInvisible() &nbsp;&nbsp; &nbsp;theWordText.isVisible = false; &nbsp;&nbsp;&nbsp; countDownText.isVisible = false; &nbsp;&nbsp;&nbsp; gameOverText.isVisible = false; &nbsp;&nbsp; &nbsp;--transition.to (gameOverText.text, { time=2000, alpha=0 }); &nbsp;&nbsp; &nbsp;timer.performWithDelay(2000, Setup); &nbsp;&nbsp; &nbsp;end end function CheckWord() &nbsp;&nbsp; &nbsp;if(#theWord \<= 1) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; return; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;local lowerCaseWord = string.lower(theWord) &nbsp;&nbsp; &nbsp;local tempBall &nbsp;&nbsp; &nbsp; if(table.indexOf(wordTable,lowerCaseWord) == nil) then &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;--print(theWord) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;instructionsText.text = "NOT A WORD!"; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;instructionsText:toFront() &nbsp;&nbsp; &nbsp; else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; for i=1, #chosenBalls do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;table.remove(allBalls,table.indexOf(allBalls,chosenBalls[i])) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;chosenBalls[i]:removeSelf(); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;chosenBalls[i] = nil; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;theWord = "" &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;theWordText.text = "" &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; print (#allBalls) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chosenBalls = {} &nbsp;&nbsp; &nbsp; end end function ResetWord() &nbsp;&nbsp;&nbsp; instructionsText.text = ""; &nbsp;&nbsp; &nbsp;theWord = '' &nbsp;&nbsp; &nbsp;theWordText.text = "" &nbsp;&nbsp; &nbsp;chosenBalls = {} end function CreateVowelBalls(number) &nbsp;&nbsp; &nbsp;for i=1, number do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CreateBall(true) &nbsp;&nbsp; &nbsp;end end function CreateSpecialChar(number) &nbsp;&nbsp; &nbsp;for i=1, number do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CreateBall(true) &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; end&nbsp;&nbsp; &nbsp; function FormString(e) &nbsp;&nbsp; &nbsp; local thisSprite = e.target &nbsp;&nbsp; &nbsp; local theLetter = thisSprite.letter; &nbsp;&nbsp; &nbsp; --if(table.indexOf(chosenBalls,thisSprite) == nil) then &nbsp;&nbsp; &nbsp; table.insert(chosenBalls,thisSprite); &nbsp;&nbsp; &nbsp; theWord = theWord .. theLetter; &nbsp;&nbsp; &nbsp; theWordText.text = theWord; &nbsp;&nbsp; &nbsp; theWordText.x = display.contentWidth/2; &nbsp;&nbsp; &nbsp; --else &nbsp;&nbsp; &nbsp; --print("You already chose that ball silly"); &nbsp;&nbsp; &nbsp; --end end &nbsp;function Explode(e) &nbsp;&nbsp;&nbsp; &nbsp;local thisSprite = e.target &nbsp;&nbsp;&nbsp; &nbsp;thisSprite.isVisible = false &nbsp;&nbsp;&nbsp; &nbsp;local randomIndex &nbsp;&nbsp;&nbsp; &nbsp;local randomBall &nbsp;&nbsp;&nbsp; &nbsp;if(#allBalls \< 5) then &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for i=1, #allBalls do &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;RemoveBall() &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for i=1, 5 do &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;RemoveBall() &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print(#allBalls) &nbsp;end &nbsp; &nbsp;function RemoveBall() &nbsp;&nbsp;&nbsp; &nbsp;local randomIndex = math.random(#allBalls) &nbsp;&nbsp;&nbsp; &nbsp;local tempBall = allBalls[randomIndex] &nbsp;&nbsp;&nbsp; &nbsp;tempBall:removeSelf() &nbsp;&nbsp;&nbsp; &nbsp;tempBall = nil &nbsp;&nbsp;&nbsp; &nbsp;table.remove(allBalls,randomIndex); &nbsp;end &nbsp; function ReadTextFile() local path = system.pathForFile( "espanol2utf8.txt", &nbsp;&nbsp;&nbsp; &nbsp;system.ResourceDirectory) local file = io.open( path, "r" ) for line in file:lines() do &nbsp;&nbsp; &nbsp;line = string.gsub(line, 1, #line - 1); &nbsp;&nbsp;&nbsp; table.insert(wordTable,line) end io.close( file ) file = nil end Setup() end &nbsp; &nbsp; -- "scene:show()" function scene:show( event ) &nbsp; &nbsp;&nbsp; local sceneGroup = self.view &nbsp;&nbsp; local phase = event.phase &nbsp; &nbsp;&nbsp; if ( phase == "will" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Called when the scene is still off screen (but is about to come on screen). &nbsp;&nbsp; elseif ( phase == "did" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Called when the scene is now on screen. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Insert code here to make the scene come alive. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Example: start timers, begin animation, play audio, etc. &nbsp;&nbsp; end end &nbsp; -- "scene:hide()" function scene:hide( event ) &nbsp; &nbsp;&nbsp; local sceneGroup = self.view &nbsp;&nbsp; local phase = event.phase &nbsp; &nbsp;&nbsp; if ( phase == "will" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Called when the scene is on screen (but is about to go off screen). &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Insert code here to "pause" the scene. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Example: stop timers, stop animation, stop audio, etc. &nbsp;&nbsp; elseif ( phase == "did" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Called immediately after scene goes off screen. &nbsp;&nbsp; end end &nbsp; -- "scene:destroy()" function scene:destroy( event ) &nbsp; &nbsp;&nbsp; local sceneGroup = self.view &nbsp; &nbsp;&nbsp; -- Called prior to the removal of scene's view ("sceneGroup"). &nbsp;&nbsp; -- Insert code here to clean up the scene. &nbsp;&nbsp; -- Example: remove display objects, save state, etc. end &nbsp; --------------------------------------------------------------------------------- &nbsp; -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) &nbsp; --------------------------------------------------------------------------------- &nbsp; return scene

Any thoughts or suggestions?

Looking at your code, I’m guessing your a C programmer. C is a two pass compiler. The first pass it goes and collects all the symbols and assigns them memory addresses on the second pass it populates the usage of those symbols correctly.

someVar = someFunction; &nbsp; .... int function someFunction() { }

is perfectly valid in C because when someVar is assigned, C will have already been through the code once and knows what someFunction is and has an address for it. Lua is a one pass system. Variables and functions have to be known before you use them. So:

local someVar = someFunction -- someFunction is currently nil, nil gets assigned to someVar ... local function someFunction() &nbsp;-- now gets a memory address, but it's too late for "someVar" end

This creates “scope” problems for quite a few developers who are new to Lua. Many people work around this by making things global, but globals are a pretty bad practice for many reasons. Most of your functions above are global which works around the scoping issues, however for your back button handler, you made it local instead of global. Obviously removing the “local” will likely solve this problem, but if you have another scene and you use the same function name, you will overwrite this function.

The correct solution is to write your code what seems backwards: write the functions before you use them. This will also give you a chance to not include as many functions inside of other functions to avoid other scope issues.

local function someFunction() -- gets a memory address and is available at this block level end ... local someVar = someFunction -- someFunction has a valid memory address

Rob

Looking at your code, I’m guessing your a C programmer. C is a two pass compiler. The first pass it goes and collects all the symbols and assigns them memory addresses on the second pass it populates the usage of those symbols correctly.

someVar = someFunction; &nbsp; .... int function someFunction() { }

is perfectly valid in C because when someVar is assigned, C will have already been through the code once and knows what someFunction is and has an address for it. Lua is a one pass system. Variables and functions have to be known before you use them. So:

local someVar = someFunction -- someFunction is currently nil, nil gets assigned to someVar ... local function someFunction() &nbsp;-- now gets a memory address, but it's too late for "someVar" end

This creates “scope” problems for quite a few developers who are new to Lua. Many people work around this by making things global, but globals are a pretty bad practice for many reasons. Most of your functions above are global which works around the scoping issues, however for your back button handler, you made it local instead of global. Obviously removing the “local” will likely solve this problem, but if you have another scene and you use the same function name, you will overwrite this function.

The correct solution is to write your code what seems backwards: write the functions before you use them. This will also give you a chance to not include as many functions inside of other functions to avoid other scope issues.

local function someFunction() -- gets a memory address and is available at this block level end ... local someVar = someFunction -- someFunction has a valid memory address

Rob