Page 1 of 1

How can I delete the miliseconds of a timer and only show the first number?

Posted: Wed Jan 19, 2022 8:50 pm
by Seth144k
I figured out how to get working the timer using this:

Code: Select all

timer = "0"
timer = timer + dt
    if timer >= 10 then
        love.event.quit()
    end
this makes a timer but it shows milliseconds also so how can i hide or not show them?

Re: How can I delete the miliseconds of a timer and only show the first number?

Posted: Wed Jan 19, 2022 10:12 pm
by darkfrei
Seth144k wrote: Wed Jan 19, 2022 8:50 pm I figured out how to get working the timer using this:

Code: Select all

timer = "0"
timer = timer + dt
    if timer >= 10 then
        love.event.quit()
    end
this makes a timer but it shows milliseconds also so how can i hide or not show them?

Code: Select all

-- init:
timer = 0 -- not "0"

-- update:
timer = timer + dt

-- draw:
love.graphics.print (math.floor(timer))
-- or
love.graphics.print (string.format("%.0f", timer))

https://www.lua.org/pil/20.html
http://lua-users.org/wiki/StringLibraryTutorial

Re: How can I delete the miliseconds of a timer and only show the first number?

Posted: Wed Jan 19, 2022 10:19 pm
by MrFariator
Darkfrei's answer works, but in order to trim away the decimals with string.format, you can actually use %d or %i.

Code: Select all

print ( string.format ( "%d", 1010.1111 ) ) -- prints string 1010
print ( string.format ( "%i", 1010.1111 ) ) -- prints string 1010