I would like my game to reset when the player taps on the Play Again button that shows on my last screen. When that button is tapped. I want the results from the last game to clear and the screen changes with director which I am using and the player can start fresh. Here is my code below for that screen. Could somebody tell me what code I can add to reset the level? I have a global variable that is being pulled from the previous screen which is then supplying this screen with an answer. I would need the result on this screen which is in numberFieldReminder to clear out when the game resets and take the person to the titlescreen.
I have everything working properly on this screen except for the reset part that would clear the screen.
Can somebody assist?
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
local inputFontSize = 80
local inputFontHeight = 80
local tHeight = 100
local ui = require(“ui”)
local number
if _G.numberSix ~= nil then
number = _G.numberSix
elseif _G.numberTen ~= nil then
number = _G.numberTen
else
number = 0
end
local screen9 = display.newImage (“screen9.png”)
localGroup:insert(screen9)
–> This sets Screen9
local playbutton = display.newImage (“play.png”)
localGroup:insert(playbutton)
playbutton.x = 100
playbutton.y = 55
playbutton.xScale = .5
playbutton.yScale = .5
local function playbuttonfn (event)
director:changeScene( “titlescreen”, “flip” )
media.playEventSound( “bloop_x.caf” )
end
playbutton:addEventListener (“tap”, playbuttonfn)
local cleanUp = function()
play:removeEventListener (“touch”, touchedPlay)
end
–setting to avoid the error
if divisionBal == nil then divisionBal = 0 end
if digitSum == nil then digitSum =0 end
– the sum value will be in digitSum
– reminder value will be in divisionBal
– show the reminder in a textfield
numberFieldReminder = native.newTextField( 180, 315, 85, tHeight, onnumberFieldReminder)
numberFieldReminder.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldReminder.inputType = “number”
numberFieldReminder.align = “center”
numberFieldReminder.text = divisionBal
localGroup:insert(numberFieldReminder)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua] [import]uid: 72372 topic_id: 14212 reply_id: 314212[/import]