Page 1 of 1

[LIBRARY] EZTimer, an easy to use timer

Posted: Fri Mar 20, 2015 4:07 pm
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!

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

Posted: Fri Mar 20, 2015 7:08 pm
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.

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

Posted: Sat Mar 21, 2015 1:58 am
by RaptrStudios
Thanks for the honesty, and yes this library is nowhere close to being done.

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

Posted: Sun Mar 22, 2015 10:58 am
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".