WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Syntax Problem (https://www.wowinterface.com/forums/showthread.php?t=45844)

Kendian 02-17-13 09:06 PM

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~

Kendian 02-17-13 09:34 PM

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)


SDPhantom 02-17-13 09:41 PM

Instead of setting a variable and only using it in one place, you could do this instead.
Code:

sStats:SetModuleText(sStats_ZoneText, GetZoneText() .. " : " .. GetSubZoneText(), "")

Kendian 02-17-13 09:56 PM

Nice, thank you!

Phanx 02-19-13 01:36 AM

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)



All times are GMT -6. The time now is 12:56 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI