I’m trying to change the displayed text on a text object from a value in a table. Everything works well in the Simulator Output, but the text does not change on the device in the Simulator itself. The summary1.text never gets updated or refreshed on the screen. What am I doing wrong?
local composer = require( “composer” )
local scene = composer.newScene()
local exerciseNum = require(‘libs.exercisedata’)
local settingsFlg = require(‘libs.settingsdata’)
function scene:create( event )
local sceneGroup = self.view
– Called when the scene’s view does not exist.
–
– INSERT code here to initialize the scene
– e.g. add display objects to ‘sceneGroup’, add touch listeners, etc.
display.setDefault(“background”, 0, 0, 1 )
– Keep track of time in seconds
local secondsLeft = settingsFlg.exerciseTimeMin * 60 – 20, 25, or 30 minutes * 60 seconds
print( “-----------------------”)
– Keep track of start time in seconds
local beginSecs = secondsLeft
print( "beginSecs = ", beginSecs)
– Keep track of Splits in number of seconds
local splitTime = settingsFlg.splitSec
print( "splitTime = ", splitTime)
print( “-----------------------”)
print( "beginSecs - splitTime = ", (beginSecs - splitTime) )
local clockText = display.newText(“30:00”, display.contentCenterX, 36, native.systemFontBold, 80)
clockText:setFillColor( 0.2, 0.2, 1 )
local i = 0
local function updateTime(summary1)
– decrement the number of seconds
secondsLeft = secondsLeft - 1
– time is tracked in seconds. We need to convert it to minutes and seconds
local minutes = math.floor( secondsLeft / 60 )
local seconds = secondsLeft % 60
– make it a string using string format.
local timeDisplay = string.format( “%02d:%02d”, minutes, seconds )
clockText.text = timeDisplay
print( "secondsLeft = ", secondsLeft)
if secondsLeft == (beginSecs - splitTime) then
print( “-----------------------”)
print( “I am at the Split test”)
beginSecs = secondsLeft
i = i + 1
print( "i = ", i )
print("exerciseNum = ", exerciseNum[i])
k = i
if k == 1 then
local summary1 = display.newText( exerciseNum[i], 100, 200, native.systemFont, 20)
summary1:setFillColor(0) – black
summary1.x = 100
summary1.y = 280
summary1.anchorX = 0
else
print( "k = ", k)
summary1.text = (exerciseNum[i])
summary1.x = 100
summary1.anchorX = 0
print( "summary1.text = ", summary1.text )
end
end
end
–function displayExercise()
– print( “-----------------------”)
–end
– run the timer
local countDownTimer = timer.performWithDelay( 1000, updateTime, secondsLeft )
– create a white background to fill screen
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 1 ) – white
– create some text
local title = display.newText( “Exercise Screen”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = 180
– all objects must be added to group (e.g. self.view)
sceneGroup:insert( bg )
sceneGroup:insert( title )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
– Called when the scene is now on screen
print( “xxxxxxxxxxxxxxxxxx”)
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
– Called when the scene is on screen and is about to move off screen
–
– INSERT code here to pause the scene
– e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == “did” then
– Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s “view” (sceneGroup)
–
– INSERT code here to cleanup the scene
– e.g. remove display objects, remove touch listeners, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
summary1.text = (exerciseNum[i])
) would be useful for you to make it easier to troubleshoot issues like this.