[LIBRARY] EZTimer, an easy to use timer

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
RaptrStudios
Prole
Posts: 39
Joined: Thu Jan 22, 2015 5:46 am

[LIBRARY] EZTimer, an easy to use timer

Post by RaptrStudios »

EZTimer is a very simple, short timing library in only 17 lines!
timer.lua
(336 Bytes) Downloaded 174 times
Remember you need to require this library!

Code: Select all

require('timer')
To make a new timer place this in the love.load() section,

Code: Select all

timer_new()
and put the desired amount of time (in seconds) between the parentheses like this,

Code: Select all

timer_new(5)
To check if the timer has completed or not, place this somewhere in the love.update(),

Code: Select all

timer_isTime(function(object)
	-- If timer is done, run this code.
end)
And finally all ways REMEMBER to place,

Code: Select all

timer_update(dt)
in the love.update().

And that's pretty much it!

Heres an example :)

Code: Select all

require('timer')

function love.load()
    timer_new(10)
end

function love.update(dt)
    timer_update(dt)
    timer_isTime(function(object)
        print('TIMER FINISHED')
    end)
end
Note: This is my first commercial library so, cut me some slack!
Last edited by RaptrStudios on Sat Mar 21, 2015 1:58 am, edited 1 time in total.
Raptr Studios
http://raptrstudios.weebly.com/

Please consider donating to us!

New Game I'm Working On - Cerradon
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: [LIBRARY] EZTimer, an easy to use timer

Post by veethree »

I'm gonna be honest, I don't think this library is particularly useful. It basically does the same thing as the following snippet,

Code: Select all

function love.load()
	timer = 14
end

function love.update(dt)
	timer = timer - dt
	if timer < 0 then
		--code
	end
end
You can definitely expand it a bit to make it useful. For example allow for multiple timers to be run simultaneously, Maybe pass a "isTime" function to timer_new, and call that function in timer_update when the time's up etc.
RaptrStudios
Prole
Posts: 39
Joined: Thu Jan 22, 2015 5:46 am

Re: [LIBRARY] EZTimer, an easy to use timer

Post by RaptrStudios »

Thanks for the honesty, and yes this library is nowhere close to being done.
Raptr Studios
http://raptrstudios.weebly.com/

Please consider donating to us!

New Game I'm Working On - Cerradon
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: [LIBRARY] EZTimer, an easy to use timer

Post by rmcode »

I suggest you read through kikito's articles on modules. I doubt many people would use a library that ignores typical conventions. This would also allow you to use nicer function names like timer.new, timer.update and maybe timer.hasFinished.

Last but not least you should use a proper license like MIT or Zlib instead of "Remember to ask before using any of this code".
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests