How would I create a timer?

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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How would I create a timer?

Post by Robin »

Just (a - b).
Help us help you: attach a .love.
User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: How would I create a timer?

Post by All0utWar »

How would I get the timer to stop and post the time when the game is over though?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How would I create a timer?

Post by Robin »

You simply stop updating a when the game is over.
Help us help you: attach a .love.
User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: How would I create a timer?

Post by All0utWar »

Robin wrote:You simply stop updating a when the game is over.
Alright, one more question. Is it possible to shorten the amount of digits in the number? Like, it goes 1.734611324. Then when I go to the end screen the number is a lot longer.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How would I create a timer?

Post by Robin »

You can use

Code: Select all

string.format('%.2f', your_number)
example:

Code: Select all

print(string.format('%.2f', 3.1290423094))
-- prints 3.13
If you want to change the number of digits to something other than 2, use that instead of 2.
Help us help you: attach a .love.
User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: How would I create a timer?

Post by All0utWar »

Robin wrote:You can use

Code: Select all

string.format('%.2f', your_number)
example:

Code: Select all

print(string.format('%.2f', 3.1290423094))
-- prints 3.13
If you want to change the number of digits to something other than 2, use that instead of 2.
So, this would go in love.update or love.draw?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How would I create a timer?

Post by Robin »

love.draw.

In love.draw, you have something like:

Code: Select all

love.graphic.print(a-b, 10, 10)
It's not exactly the same what you have, but it's basically comparable.

Now, instead you do

Code: Select all

love.graphic.print(string.format("%.2f", a-b), 10, 10)
Adjust as needed.
Help us help you: attach a .love.
User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: How would I create a timer?

Post by All0utWar »

Wow, I feel like a complete retard for not seeing how easy this is.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: How would I create a timer?

Post by tentus »

All0utWar wrote:Wow, I feel like a complete retard for not seeing how easy this is.
Don't worry, everyone who writes code goes through that. I go feel that way about once a month. :P
Kurosuke needs beta testers
User avatar
All0utWar
Prole
Posts: 17
Joined: Tue Dec 06, 2011 12:36 am

Re: How would I create a timer?

Post by All0utWar »

Okay well, these should be the last few questions in THIS thread. (I hope) Anyway, whenever I take b out of the timer, the time changes from what it was while playing. It's like the time just says how much time it took to load the game and when I go back to play and then go to the end game screen, the time is the same as the last time I went to the screen. Second question, how do I make it so the timer only starts when the player presses the enter key and then the timer starts at 0 at the start of a new game?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests