Thread Tools Display Modes
08-02-08, 09:48 PM   #1
Eleuthria
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 5
Adding a delay to an addon?

I'm working on an addon which grabs some information from /who requests which are going to be sent by the addon.

How can I make it so it sends the different /who requests every 'X' seconds, since you can't send multiple requests back-to-back.
  Reply With Quote
08-02-08, 10:29 PM   #2
Freki
A Deviate Faerie Dragon
 
Freki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 18
Originally Posted by Eleuthria View Post
I'm working on an addon which grabs some information from /who requests which are going to be sent by the addon.

How can I make it so it sends the different /who requests every 'X' seconds, since you can't send multiple requests back-to-back.
You'll have to use the OnUpdate handler.
Example (using no XML)

Code:
local MyAddon = CreateFrame("frame")

local elapsed = 0
function MyAddon:OnUpdate(update)
     elapsed = elapsed + update
     if (elapsed > 3) then
          SendWho("Doomchicken")
          elapsed = 0
     end
end

MyAddon:SetScript("OnUpdate", function(self, update) self:OnUpdate(update) end)
Since OnUpdate is called every... 0.05 sec or so, you might want to disable it when you're not using it via MyAddon:SetScript("OnUpdate", nil)
  Reply With Quote
08-02-08, 10:34 PM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Add all new requests to a queue and create an OnUpdate handler and sum up the "elapsed" parameter (this is the time since the last OnUpdate).

example:

Code:
queue = {}
table.insert(queue, "request1")
table.insert(queue, "request2")
table.insert(queue, "request3")
table.insert(queue, "request4")
...

local OnUpdateTimer = 0
local ActionTimer = 10

function OnUpdateHandler(elapsed)
	OnUpdateTimer = OnUpdateTimer + elapsed
	if OnUpdateTimer > ActionTimer then
		OnUpdateTimer = 0
		if table.getn(queue) > 0 then
			SendWhoblablabla(queue[1])
			table.remove(queue, 1)
		end
	end
end

Last edited by Duugu : 08-02-08 at 10:37 PM.
  Reply With Quote
08-02-08, 10:40 PM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by Freki View Post
Since OnUpdate is called every... 0.05 sec or so
afaik OnUpdate is called on every rendered frame. This could be every 0.05, once a minute or potentially never - depends on your frame rate.
  Reply With Quote
08-02-08, 10:50 PM   #5
Eleuthria
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 5
Thank you very much, worked like a charm and hopefully my little addon will be taking over the world shortly .
  Reply With Quote
08-02-08, 11:51 PM   #6
Freki
A Deviate Faerie Dragon
 
Freki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 18
Originally Posted by Duugu View Post
afaik OnUpdate is called on every rendered frame. This could be every 0.05, once a minute or potentially never - depends on your frame rate.
Still gets the point across If someone is getting 1 frame per minute I think the last thing they want is a mod that does work when it doesn't need to on that frame lol
  Reply With Quote
08-03-08, 12:45 AM   #7
Jzar
A Chromatic Dragonspawn
 
Jzar's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 158
Also consider using the WhoLib library off of WoWAce. This is used to queue up all /who requests from any addon, guarantee that they are sent, and then pass the info back to the calling addon. Would make your mod work well with Prat or other addons that can hog /who bandwidth.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Adding a delay to an addon?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off