Okay so here is what I put in love.draw:
love.graphics.printf('You have survived for' ..getDelta().. ' !', 0, 215, 620, 'center')
Here is what I put in love.update(dt):
dt = love.timer.getDelta()
Then, when I run the game I get an error that says, 'attempt to call global 'getDelta' (a nil value)' How do I do this?
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.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How would I create a timer?
dt is already defined as a global. You don't have to define it again.
Re: How would I create a timer?
Oh okay, do you know how to make a timer using getDelta though?Jasoco wrote:dt is already defined as a global. You don't have to define it again.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How would I create a timer?
Edit: Here's a Helper Library with a Timer in it you can check out on the Wiki:
http://love2d.org/wiki/hump
-- Original post follows --
The basics are as follows:
(All variable names are arbitrary and just for sample purposes. This is just to show off the logic of how it works.)
That's the gist of it. I think someone might have created a library.
Alternatively:
I'm sure someone has created a library. Maybe they can post it. I haven't checked the Wiki.
http://love2d.org/wiki/hump
-- Original post follows --
The basics are as follows:
(All variable names are arbitrary and just for sample purposes. This is just to show off the logic of how it works.)
Code: Select all
--First you define the timer.
timerStart = love.timer.getTime()
--In your update, you use something like this:
if love.timer.getTime() - timerStart >= timerCountdown then
--DO YOUR THING
end
Alternatively:
Code: Select all
--First you define the counter.
counter = 0
--In your update, you use something like this:
counter = counter + dt
if counter >= counterLimit then
--DO YOUR THING
end
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How would I create a timer?
From the example you used, I would look at love.timer.getTime before using love.timer.getDelta.
Kurosuke needs beta testers
Re: How would I create a timer?
I've looked at that already and I don't understand where it goes or how it is done.tentus wrote:From the example you used, I would look at love.timer.getTime before using love.timer.getDelta.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How would I create a timer?
getDelta doesn't need to be called unless you're trying to use Delta in a function that doesn't have the dt variable available to it. By defauly, dt is passed into update() and you can pass it on to any other functions inside that function if you have to. But if you happen to NEED to use it elsewhere like in draw() or one of its children, you should call it.tentus wrote:From the example you used, I would look at love.timer.getTime before using love.timer.getDelta.
Personally, and I've said it once before, I use my own modified version of love.run() which makes dt global instead of local so you don't have to pass it anymore. But that's just me. I'm unconventional.
Just use HUMP or play around with my coded methods.
Re: How would I create a timer?
Oh wow, actually that was super easy to figure out after I looked at it for 5 minutes.tentus wrote:From the example you used, I would look at love.timer.getTime before using love.timer.getDelta.
EDIT: How would I make it so that after the game ends, it shows the time? Everytime I do it I get 0 seconds.
http://pastebin.com/38CabixA
- 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 set both a and b each frame. You'll want to set b in love.load only and a in love.update. Do you see why?
Help us help you: attach a .love.
Re: How would I create a timer?
Yeah now I understand, thanks!Robin wrote:You set both a and b each frame. You'll want to set b in love.load only and a in love.update. Do you see why?
EDIT: Okay, I understand how to get the timer working, but how would I show the time at the end? I tried to do these things and it won't work:
love.graphics.printf('You survived for ' .. love.timer.getMicro() .. ' seconds!', 0, 215, 620, 'center')
love.graphics.printf('You survived ' .. love.timer.getMicro(a-b) .. ' seconds!', 0, 215, 620, 'center')
love.graphics.printf('You survived for ' .. getMicroTime(a-b) .. ' seconds!', 0, 215, 620, 'center')
love.graphics.printf('You survived for ' .. getMicroTime() .. ' seconds!', 0, 215, 620, 'center')
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 3 guests