Corona SDK How to Save Timer Text?

Is there a way to save the CountUp timer after finishing the scene as a text to other lua file? But im having an error with SaveTimer.lua on text=currentTime it said bad argument on newText. What will happen is after using timer.lua it will save its counUpText on my SaveTimer.lua

SaveTimer.lua

local time\_label = display.newText({parent=uiGroup, text=currenTime, font=native.systemFontBold, fontSize=128, align="center"}) time\_label.x = 540 time\_label.y = 750 time\_label:setFillColor(0.9,0.9,0)

Timer.lua

currentTime local gameTime = 0 function startTimer() clockTimer = timer.performWithDelay(1000,doCountUp,gameTime) end function doCountUp() currentTime = countUpText.text currentTime = currentTime +1 countUpText.text = currentTime if(currentTime == 0) then countUpText.text = currentTime startTimer() end end countUpText = display.newText(gameTime,259,50,native.systemFontBold,100) countDownText:setTextColor("#000000")
local time\_label = display.newText({parent=uiGroup, text=currenTime, font=native.systemFontBold, fontSize=128, align="center"})

Typo… try

local time_label = display.newText({parent=uiGroup, text= currentTime , font=native.systemFontBold, fontSize=128, align=“center”})

Your code really needs changing.  For example calling 

timer.performWithDelay(1000,doCountUp,gameTime)

when gameTime = 0 will mean doCountUp will fire every second for ever and this can cause your app to crash if objects are unloaded (but the timer is still active).

This is a better way of coding what you want

--declare as global so visible in other lua files (although better to be local and passed as a parameter to saveTimer.lua) currentTime = 0 local countUpText = display.newText("0",259,50,native.systemFontBold,100) countUpText:setTextColor(0,0,0) function doCountUp() currentTime = currentTime + 1 countUpText.text = currentTime --if we are still running then... timer.performWithDelay(1000,doCountUp) --other wise just bail end function startTimer() currentTime = 0 timer.performWithDelay(1000,doCountUp) end

Thank you, I already set my currentTime as Global but still i have an error in SaveTimer.lua Error: Bad argument to ‘newText’ String Expected got nil. text = currentTime this is only my problem always have an error even though my currentTime variable is set as a global.

Thanks for reminding still got the same error lol.

local currentTime = 0 local gameTime = 0 function startTimer() clockTimer = timer.performWithDelay(1000,doCountUp,gameTime) end function doCountUp() currentTime = countUpText.text currentTime = currentTime +1 countUpText.text = currentTime if(currentTime == 0) then countUpText.text = currentTime startTimer() end end startTimer() countUpText = display.newText(gameTime,259,50,native.systemFontBold,100) --countDownText:setTextColor("#000000") local function saveit() local time\_label = display.newText({parent=uiGroup, text=currentTime, font=native.systemFontBold, fontSize=128, align="center"}) time\_label.x = 540 time\_label.y = 750 time\_label:setFillColor(0.9,0.9,0) end saveit()

Running this didn’t give me an error.

local time\_label = display.newText({parent=uiGroup, text=currenTime, font=native.systemFontBold, fontSize=128, align="center"})

Typo… try

local time_label = display.newText({parent=uiGroup, text= currentTime , font=native.systemFontBold, fontSize=128, align=“center”})

Your code really needs changing.  For example calling 

timer.performWithDelay(1000,doCountUp,gameTime)

when gameTime = 0 will mean doCountUp will fire every second for ever and this can cause your app to crash if objects are unloaded (but the timer is still active).

This is a better way of coding what you want

--declare as global so visible in other lua files (although better to be local and passed as a parameter to saveTimer.lua) currentTime = 0 local countUpText = display.newText("0",259,50,native.systemFontBold,100) countUpText:setTextColor(0,0,0) function doCountUp() currentTime = currentTime + 1 countUpText.text = currentTime --if we are still running then... timer.performWithDelay(1000,doCountUp) --other wise just bail end function startTimer() currentTime = 0 timer.performWithDelay(1000,doCountUp) end

Thank you, I already set my currentTime as Global but still i have an error in SaveTimer.lua Error: Bad argument to ‘newText’ String Expected got nil. text = currentTime this is only my problem always have an error even though my currentTime variable is set as a global.

Thanks for reminding still got the same error lol.

local currentTime = 0 local gameTime = 0 function startTimer() clockTimer = timer.performWithDelay(1000,doCountUp,gameTime) end function doCountUp() currentTime = countUpText.text currentTime = currentTime +1 countUpText.text = currentTime if(currentTime == 0) then countUpText.text = currentTime startTimer() end end startTimer() countUpText = display.newText(gameTime,259,50,native.systemFontBold,100) --countDownText:setTextColor("#000000") local function saveit() local time\_label = display.newText({parent=uiGroup, text=currentTime, font=native.systemFontBold, fontSize=128, align="center"}) time\_label.x = 540 time\_label.y = 750 time\_label:setFillColor(0.9,0.9,0) end saveit()

Running this didn’t give me an error.