You are not logged in.

Applications: [GameMaster: OPEN] | [Volunteer Testers: OPEN]


This forum will be permanently shut down on Friday 13.07.2018
Please copy or save all important information from old forum before they will be deactivated
We have moved to new board. https://forum.runesofmagic.gameforge.com/Come join us.

Peryl

Intermediate

  • "Peryl" started this thread

Posts: 313

Location: Elsewhere

  • Send private message

1

Wednesday, February 22nd 2012, 2:39am

[Library] LibTimers

Here's a little something I wrote up as an example of using/creating timers, as well as creating a library. As such, it can also stand as an example of using LibStub for your own libraries.

The code is written so that the API works in an object-oriented fashion and so this can also serve as a bit of an example on doing OOP style code (though it doesn't do full OOP style class declarations).


[SIZE=+2]LibTimers[/SIZE]
A general library for the creation and use of timers in Runes of Magic.

LibTimers is designed so that it can be used either as a stand-alone library add-on or be embedded into other add-ons without interference, or code duplication. That is, only one copy of the library resides in memory even if both methods are present.

The ZIP file provided here acts as a stand-alone version, but the Lua file can be included into other projects.

LibTimers requires the use of LibStub (provided).

See the file Manual.txt for full usage and API description.


[SIZE=+2]Example Usage[/SIZE]
The following will get the library (via LibStub) then create and start a repeating 5 second timer.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Get a reference to the library
local Lib = LibStub("LibTimers")
if not Lib then
    DEFAULT_CHAT_FRAME:AddMessage("LibTimers not found, aborting")
    return
end

local function TimerCallback()
    DEFAULT_CHAT_FRAME:AddMessage("Tick!")
end

-- Create a timer object
local Timer = Lib:CreateTimer()

-- Set the timer to repeat every 5 seconds
Timer:SetDuration(5)
Timer:SetMode(Lib.Modes.REPEATING)

-- Set a function for the timer to call 
Timer:SetCallback(TimerCallback)

-- Start the timer
Timer:Start()
Peryl has attached the following file:
  • LibTimers.zip (5.56 kB - 20 times downloaded - latest: Apr 15th 2015, 4:02pm)
2013... The year from hell....

2

Wednesday, February 22nd 2012, 2:07pm

Thanks, it's useful!
But Manual.txt need to change typesetting.
It's not easy to read.

---------------------------------
Ok, I use the software for edit, and I can read it now. ;)
Thank you!

Peryl

Intermediate

  • "Peryl" started this thread

Posts: 313

Location: Elsewhere

  • Send private message

3

Wednesday, February 22nd 2012, 11:08pm

Quoted from "matif;511970"

Thanks, it's useful!
But Manual.txt need to change typesetting.
It's not easy to read.

---------------------------------
Ok, I use the software for edit, and I can read it now. ;)
Thank you!

It's a straight ANSI text file. No line is longer than 80 characters. Not much typesetting to be done to it.

Edit Took a look in a hex editor. It has Unix line endings not DOS/Windows ones. Ah well, I run Linux :D
2013... The year from hell....