How would I create a timer?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How would I create a timer?
How would I get the timer to stop and post the time when the game is over though?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How would I create a timer?
You simply stop updating a when the game is over.
Help us help you: attach a .love.
Re: How would I create a timer?
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.Robin wrote:You simply stop updating a when the game is over.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How would I create a timer?
You can use
example:
If you want to change the number of digits to something other than 2, use that instead of 2.
Code: Select all
string.format('%.2f', your_number)
Code: Select all
print(string.format('%.2f', 3.1290423094))
-- prints 3.13
Help us help you: attach a .love.
Re: How would I create a timer?
So, this would go in love.update or love.draw?Robin wrote:You can useexample:Code: Select all
string.format('%.2f', your_number)
If you want to change the number of digits to something other than 2, use that instead of 2.Code: Select all
print(string.format('%.2f', 3.1290423094)) -- prints 3.13
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How would I create a timer?
love.draw.
In love.draw, you have something like:
It's not exactly the same what you have, but it's basically comparable.
Now, instead you do
Adjust as needed.
In love.draw, you have something like:
Code: Select all
love.graphic.print(a-b, 10, 10)
Now, instead you do
Code: Select all
love.graphic.print(string.format("%.2f", a-b), 10, 10)
Help us help you: attach a .love.
Re: How would I create a timer?
Wow, I feel like a complete retard for not seeing how easy this is.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How would I create a timer?
Don't worry, everyone who writes code goes through that. I go feel that way about once a month.All0utWar wrote:Wow, I feel like a complete retard for not seeing how easy this is.
Kurosuke needs beta testers
Re: How would I create a timer?
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?
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests