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
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.
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.