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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

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

Post 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?
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

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

Post 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
Last edited by darkfrei on Wed Jan 19, 2022 10:20 pm, edited 1 time in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests