Thread Tools Display Modes
02-17-13, 09:06 PM   #1
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Syntax Problem

Hiyas, all. This has me stumped, so forgive me if it's an obvious question. I have a small add on I wrote to go with Seerah's lovely Sstats add on. Sstats Zone. I'm trying to change the syntax of the readout to display zone AND subzone. The problem comes in when I try to separate them with a colon, like so.

Zone:Subzone.
What I end up with are syntax errors, or just ZoneSubzone, no colon. Here is the code I have. I know it's something simple, but I can't find it.

Code:
local sStats_Zone, sStats_ZoneText = sStats:CreateModule("Zone")


local ZoneText = CreateFrame("Frame")
ZoneText:Hide()
ZoneText:SetScript("OnUpdate", function(self, elapsed)
                  Subzone = GetMinimapZoneText()
                  zone = GetZoneText()
                  sStats:SetModuleText(sStats_ZoneText, zone, Subzone, ":")
            end)

-- Initialize
sStats.RegisterCallback(sStats_Zone, "sStats_Modules_Ready", function()

		ZoneText:Show()

end)
My thanks, for any/all help~
__________________
  Reply With Quote
02-17-13, 09:34 PM   #2
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
I'm dim. I figured it out.
Code:
local sStats_Zone, sStats_ZoneText = sStats:CreateModule("Zone")


local ZoneText = CreateFrame("Frame")
ZoneText:Hide()
ZoneText:SetScript("OnUpdate", function(self, elapsed)
                  zone = GetZoneText() .. " : " .. GetSubZoneText()
                  sStats:SetModuleText(sStats_ZoneText, zone, "")
            end)

-- Initialize
sStats.RegisterCallback(sStats_Zone, "sStats_Modules_Ready", function()

		ZoneText:Show()

end)
__________________
  Reply With Quote
02-17-13, 09:41 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Instead of setting a variable and only using it in one place, you could do this instead.
Code:
sStats:SetModuleText(sStats_ZoneText, GetZoneText() .. " : " .. GetSubZoneText(), "")
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-17-13, 09:56 PM   #4
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Nice, thank you!
__________________
  Reply With Quote
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

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Syntax Problem


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