Text or string value does not change on display

I have 2 variables : wave and zombies.

The value of zombies is equal to the value of waves.

 I also have a button which when you tap on it, the number of zombies will decrease by 1 and then printed it in the console.

However when I click on the button, the value of zombies is decreased by 1 but on the display, the text doesnt change.

How can I make the text update when the value of zombies has changed?

Here is my code:

local wave = 1 local zombies = wave local function lowerzombies() zombies=zombies-1 print(zombies) end local circle = display.newCircle(display.contentCenterX,display.contentCenterY+70,40) circle:addEventListener("tap",lowerzombies) local waveText = display.newText(wave, display.contentCenterX, 100, native.systemFontBold, 25) local waveTitle = display.newText("Wave:", waveText.x, waveText.y-20, native.systemFontBold, 25) local zombiesText = display.newText(zombies, display.contentCenterX, 175, native.systemFontBold, 25) local zombiesTitle = display.newText("Zombies:", zombiesText.x, zombiesText.y-20, native.systemFontBold, 20)

You have to do it yourself.
 

zombiesText.text = tostring(zombies)

There is ‘automatic watch’ capability.

You could set it up yourself though:
 

function zombiesText.enterFrame( self ) self.text = tostring(zombies) end Runtime:addEventListener("enterFrame", zombiesText ) function zombiesText.finalize( self ) Runtime:removeEventListener( "enterFrame", self ) end zombiesTest:addEventListener("finalize")

Thanks! It worked!

However, I had to change zombiesTest to zombiesText

You have to do it yourself.
 

zombiesText.text = tostring(zombies)

There is ‘automatic watch’ capability.

You could set it up yourself though:
 

function zombiesText.enterFrame( self ) self.text = tostring(zombies) end Runtime:addEventListener("enterFrame", zombiesText ) function zombiesText.finalize( self ) Runtime:removeEventListener( "enterFrame", self ) end zombiesTest:addEventListener("finalize")

Thanks! It worked!

However, I had to change zombiesTest to zombiesText