I'm trying to convert ms (2 minutes) to minutes and seconds in this format: 2:00
local timer = 120000
local minutes = 2
local seconds = 0
local milliseconds = 0
function convertTime ( ms )
if ( ms and type ( ms ) == "number" ) then
local milliseconds = math.floor((ms % 1000) / 100)
local seconds = math.floor((ms / 1000) % 60)
local minutes = math.floor((ms / (1000 * 60)) % 60)
return minutes, seconds, milliseconds
end
end
setTimer (
function ( )
timer = timer - 10
minutes, seconds, milliseconds = convertTime(timer)
end
,1000, 1
) --- added a timer which deduct 1 ms from the 2 minutes timer every seconds
If I add milliseconds to the dxDrawText then it's display in this format: 1:599, 1:598, 1:597, 1:596 etc...
dxDrawText(minutes..":"..seconds..milliseconds, screenW * 0.8443, screenH * 0.9148, screenW * 0.9740, screenH * 0.9769, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
But if I skip the milliseconds variable then it just display one zero at the start (2:0) and if reaches 1:0 I want to display in this format: 2:00, 1:00
dxDrawText(minutes..":"..seconds, screenW * 0.8443, screenH * 0.9148, screenW * 0.9740, screenH * 0.9769, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)