Refresh Numbers

Hey, everyone so I had a quick question.

local lvl = lvlNum --- A file that contains lvl local EXP = (1.25\*(lvl^3)) local showExp = display.newText( ""..EXP, 480, 100, "calibri.ttf", 35 ) local function rankUp(event) if EXP \< playerEXP then lvl = lvl + 1 lvlTxt.text = string.format("%d", lvl) end end Runtime:addEventListener("enterFrame", rankUp)

is there a way for the EXP to check when the number has increased so the whole exp changes to the number it is supposed to be. Because the level can increase, but the EXP stays the same 

Wrap changes to the value you want to monitor in a write/read function/s or timer so when the variable changes you can notify of the change. Example:

-- Declare a variable which needs to be checked local aVar = 0 -- Notify the system exactly when the variable changes by controlling it's value with a write function local function inc( amount ) aVar = aVar + amount Runtime:dispatchEvent{ name="increase", variable=aVar } end -- Notify the system on timer, incurs time penalty to avoid firing the timer constantly local \_prevValue = aVar local someTimer = timer.performWithDelay( 250, function() if (\_prevValue ~= aVar) then Runtime:dispatchEvent{ name="change", previous=\_prevValue, current=aVar } end end, 0 )

Would I have to add that into my code or will it be similar to it? Like instead of aVar I change it into the lvl variable that contains all the information right?

Yes; Change it to suit your code.

@horacebury Thank you so much! I will check this once I get home (: I was struggling to find a way to achieve this 

Wrap changes to the value you want to monitor in a write/read function/s or timer so when the variable changes you can notify of the change. Example:

-- Declare a variable which needs to be checked local aVar = 0 -- Notify the system exactly when the variable changes by controlling it's value with a write function local function inc( amount ) aVar = aVar + amount Runtime:dispatchEvent{ name="increase", variable=aVar } end -- Notify the system on timer, incurs time penalty to avoid firing the timer constantly local \_prevValue = aVar local someTimer = timer.performWithDelay( 250, function() if (\_prevValue ~= aVar) then Runtime:dispatchEvent{ name="change", previous=\_prevValue, current=aVar } end end, 0 )

Would I have to add that into my code or will it be similar to it? Like instead of aVar I change it into the lvl variable that contains all the information right?

Yes; Change it to suit your code.

@horacebury Thank you so much! I will check this once I get home (: I was struggling to find a way to achieve this