Quantcast
WoWInterface - View Single Post - Syntax Problem
Thread: Syntax Problem
View Single Post
02-19-13, 01:36 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
However, repeating that on every frame draw ever (by using an OnUpdate script) is reeeeally inefficient. You should register for the events that fire when you change zones or subzones and, since the API doesn't always return the updated values immediately when the events fire, use the OnUpdate script to add a 1/10 second delay or so:

Code:
local sStats_Zone, sStats_ZoneText = sStats:CreateModule("Zone")
local f = CreateFrame("Frame")
local e = 0

f:Hide()
f:SetScript("OnUpdate", function(self, elapsed)
	e = e + elapsed
	if e > 0.1 then
		sStats:SetModuleText(sStats_ZoneText, GetZoneText() .. " : " .. GetSubZoneText(), "")
		self:Hide()
	end
end)

f:SetScript("OnEvent", function(self, event, ...)
	e = 0
	self:Show()
end)

sStats.RegisterCallback(sStats_Zone, "sStats_Modules_Ready", function()
	f:RegisterEvent("PLAYER_ENTERING_WORLD")
	f:RegisterEvent("ZONE_CHANGED")
	f:RegisterEvent("ZONE_CHANGED_INDOORS")
	f:RegisterEvent("ZONE_CHANGED_NEW_AREA")

	e = 0
	f:Show()
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote