Page 2 of 3

Re: How would I create a timer?

Posted: Fri Dec 23, 2011 6:34 pm
by Robin
Just (a - b).

Re: How would I create a timer?

Posted: Fri Dec 23, 2011 6:38 pm
by All0utWar
How would I get the timer to stop and post the time when the game is over though?

Re: How would I create a timer?

Posted: Fri Dec 23, 2011 9:26 pm
by Robin
You simply stop updating a when the game is over.

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 12:10 am
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.

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 12:24 am
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.

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 12:33 am
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?

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 12:38 am
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.

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 12:45 am
by All0utWar
Wow, I feel like a complete retard for not seeing how easy this is.

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 1:53 am
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

Re: How would I create a timer?

Posted: Sat Dec 24, 2011 4:47 am
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?