WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   UnitBuff help (https://www.wowinterface.com/forums/showthread.php?t=49287)

10leej 05-12-14 10:42 PM

UnitBuff help
 
So finally making aura for my group frames after I found what seemed like a great example but I'm a bit stuck. The example I found uses (select(4,UnitBuff("player","AURANAME))) So I think I can use "group" but obviously it doesn't work. Do I have to repeat the event checkfor party and raid? I'm using ouf for the raid frames


Indicater script
Lua Code:
  1. if cfg.indicators.enable then
  2.         indicatorframe = CreateFrame("Frame","IndicatorFrame",self)
  3.         indicatorframe:SetPoint('TOPLEFT')
  4.         indicatorframe:SetPoint('BOTTOMRIGHT')
  5.         indicatorframe:EnableMouse(0)--disable mouse
  6.  
  7.         --Build the indicator
  8.         indicator1 = CreateFrame(nil, 'OVERLAY')
  9.         indicator1:SetPoint("TOPLEFT",indicatorframe,0,0)
  10.         indicator1:SetWidth(5)
  11.         indicator1:SetHeight(5)
  12.         indicator1:SetBackdrop({bgFile="Interface\\Buttons\\WHITE8x8"})
  13.  
  14.         indicator2 = CreateFrame(nil, 'OVERLAY')
  15.         indicator2:SetPoint("TOPRIGHT",indicatorframe,0,0)
  16.         indicator2:SetWidth(5)
  17.         indicator2:SetHeight(5)
  18.         indicator2:SetBackdrop({bgFile="Interface\\Buttons\\WHITE8x8"})
  19.  
  20.         indicator3 = CreateFrame(nil, 'OVERLAY')
  21.         indicator3:SetPoint("BOTTOMLEFT",indicatorframe,0,0)
  22.         indicator3:SetWidth(5)
  23.         indicator3:SetHeight(5)
  24.         indicator3:SetBackdrop({bgFile="Interface\\Buttons\\WHITE8x8"})
  25.  
  26.         indicator4 = CreateFrame(nil, 'OVERLAY')
  27.         indicator4:SetPoint("BOTTOMRIGHT",indicatorframe,0,0)
  28.         indicator4:SetWidth(5)
  29.         indicator4:SetHeight(5)
  30.         indicator4:SetBackdrop({bgFile="Interface\\Buttons\\WHITE8x8"})
  31.  
  32.         --Show Hide
  33.         indicatorframe:SetScript("OnEvent", function(self, OnEvent)
  34.             if event == "UNIT_AURA" then
  35.                 indicator1 = (select(4,UnitBuff("party",cfg.indicators.aura1)))
  36.             elseif event == "UNIT_AURA" then
  37.                 indicator2 = (select(4,UnitBuff("party",cfg.indicators.aura2)))
  38.             elseif event == "UNIT_AURA" then
  39.                 indicator3 = (select(4,UnitBuff("party",cfg.indicators.aura3)))
  40.             elseif event == "UNIT_AURA" then
  41.                 indicator4 = (select(4,UnitBuff("party",cfg.indicators.aura4)))
  42.             elseif indicator1 == nil then
  43.                 indicator1:Hide()
  44.             elseif indicator2 == nil then
  45.                 indicator2:Hide()
  46.             elseif indicator3 == nil then
  47.                 indicator3:Hide()
  48.             elseif indicator4 == nil then
  49.                 indicator4:Hide()
  50.             end
  51.         end)
  52.         indicator1:RegisterEvent("UNIT_AURA")
  53.         indicator2:RegisterEvent("UNIT_AURA")
  54.         indicator3:RegisterEvent("UNIT_AURA")
  55.         indicator4:RegisterEvent("UNIT_AURA")
  56.     end

SVN is currently down for some reason can't post to it, so here's pastebin
config
http://pastebin.com/d32JQuK8
group frame code
http://pastebin.com/SJEzm9xn

semlar 05-12-14 11:00 PM

First of all, your event handler will never fire because it's on "indicatorframe" and you're registering UNIT_AURA events for everything except the frame with your actual event handler.

The frame you have SetScript('OnEvent') on is what you need to register the event for.

Secondly, nothing past your first if statement in the event handler is going to be called.

You're only watching one event, so there's no point in checking what event is being fired, and all of your else conditions are identical to the first condition, so if it's true it will never get to them.

Also, checking "if indicator1 == nil" then attempting to HIDE indicator1 will result in an error if that frame doesn't actually exist.

edit: Actually I just reread it and I guess you named the result of the UnitBuff function the same thing as your frames, which would half explain that part.

Phanx 05-13-14 06:59 AM

Also:

All of those "indicatorframe" and "indicatorN" variables are globals, which is not so great, and "IndicatorFrame" is a pretty bad global object name too... especially since you're using the same globals for every unit's indicator frame.

You're using CreateFrame wrong when you create the indicators -- you're passing nil and "OVERLAY" which would be fine if those were texture or fontstring creations, but not for a frame. You need to pass a frame type (eg. "Frame"), a name (should be nil here), and a parent (should be self here).

You're also passing "party" to UnitBuff, but "party" is not a valid unit token, and you don't want to hardcode a unit here, because it looks like you're intending for these indicators to be added to multiple units' frames.

Lua is case-sensitive, so "indicatorframe" and "indicatorFrame" are not the same thing -- you should be getting a nil value error from your SetScript line, since "indicatorFrame" is not defined as a frame or anything else.

Change your whole indicator section to this:
Code:

        if cfg.indicators.enable then
                local indicators = CreateFrame("Frame", nil ,self)
                indicators:SetAllPoints(true)
                indicators:EnableMouse(false)
                self.indicators = indicators

                -- Build the indicators
                for i = 1, #indicatorPositions do
                        local position = indicatorPositions[i]
                        local indicator = CreateFrame("Frame", nil, indicators)
                        indicator:SetPoint(position)
                        indicator:SetSize(5, 5)
                        indicator:SetBackdrop(indicatorBackdrop)

                        indicator.aura = cfg.indicators["aura"..i]
                        indicators[position] = indicator
                end

                -- Register the event on the frame itself
                self:RegisterEvent("UNIT_AURA", UpdateIndicators)
        end

And add this outside and above your spawn function:
Code:

local indicatorPositions = { "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" }
local indicatorBackdrop = { bgFile = "Interface\\Buttons\\WHITE8X8" }
local function UpdateIndicators(self, event, unit)
        for i = 1, #indicatorPositions do
                local position = indicatorPositions[i]
                local indicator = indicators[position]
                indicator:SetShown(UnitBuff(unit, indicator.aura))
        end
end


10leej 05-14-14 05:06 AM

ok so bugsack is dropping this error on me
Code:

2x oUF_Bob-1.1\modules\group-Group.lua:185: attempt to get length of global "indicatorPositions" (a nil value)
<in C code>
<in C code>
FrameXML\RestrictedFrames.lua:604: in function <FrameXML\RestrictedFrames.lua:603>
FrameXML\RestrictedFrames.lua:742: in function "CallMethod"
[string "                local header = self:GetParent()RestrictedExecution.lua:441: in function <FrameXML\RestrictedExecution.lua:412>
FrameXML\SecureGroupHeaders.lua:116: in function <FrameXML\SecureGroupHeaders.lua:110>
FrameXML\SecureGroupHeaders.lua:166: in function <FrameXML\SecureGroupHeaders.lua:123>
FrameXML\SecureGroupHeaders.lua:488: in function <FrameXML\SecureGroupHeaders.lua:387>
<in C code>
FrameXML\SecureStateDriver.lua:100: in function <FrameXML\SecureStateDriver.lua:95>
FrameXML\SecureStateDriver.lua:164: in function <FrameXML\SecureStateDriver.lua:146>
<in C code>
FrameXML\SecureStateDriver.lua:11: in function "RegisterAttributeDriver"
oUF-1.6.6\ouf-1.6.6.lua:533: in function "SpawnHeader"
oUF_Bob-1.1\modules\group-Group.lua:216: in function "func"
oUF-1.6.6\factory.lua:20: in function <oUF\factory.lua:16>
(tail call): ?

Locals:
nil

code

not sure what to do about that as it's a bit beyond me >.>

semlar 05-14-14 05:18 AM

You can't access a local variable before it's declared.

So you need to move these..
Lua Code:
  1. local indicatorPositions = { "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" }
  2. local indicatorBackdrop = { bgFile = "Interface\\Buttons\\WHITE8X8" }
  3. --Spawn Indicators
  4. local function UpdateIndicators(self, event, unit)
  5.         for i = 1, #indicatorPositions do
  6.                 local position = indicatorPositions[i]
  7.                 local indicator = indicators[position]
  8.                 indicator:SetShown(UnitBuff(unit, indicator.aura))
  9.         end
  10. end
to somewhere above this..
Lua Code:
  1. local function Shared(self, unit, isSingle)
Because you access those variables inside of that function.

10leej 05-14-14 05:32 AM

I figured that but when I do that I get an ouf error. but not a lua error.
Code:

oUF: Error: Style [BobGroup] attempted to register event [UNIT_AURA] on unit [raid] with a handler that doesn't exist.
also if I move all those lines above the shared function I wind up getting this error when I cast Power Word Shield, which should be one of my indicators according to my config unless it's indexing by spell id ad not name now
Code:

10x oUF_Bob-1.1\modules\group-Group.lua:24: attempt to index global "indicators" (a nil value)
oUF_Bob-1.1\modules\group-Group.lua:24: in function <oUF_Bob\modules\group.lua:21>
(tail call): ?

Locals:
(*temporary) = "UNIT_AURA"
(*temporary) = "party1"
(*temporary) = "UNIT_AURA"
(*temporary) = "party1"
(*temporary) = <function> defined =[C]:-1


semlar 05-14-14 05:42 AM

Well, I don't know anything about oUF, but either you didn't put the "UpdateIndicators" function above the "Shared" function or it needs a global name, in which case you're going to want to rename it to something more unique like "BobsIndicatorUpdater" and fix 'self:RegisterEvent("UNIT_AURA", UpdateIndicators)' to reflect the new name.

10leej 05-14-14 05:48 AM

Quote:

Originally Posted by semlar (Post 292763)
Well, I don't know anything about oUF, but either you didn't put the "UpdateIndicators" function above the "Shared" function or it needs a global name, in which case you're going to want to rename it to something more unique like "BobsIndicatorUpdater" and fix 'self:RegisterEvent("UNIT_AURA", UpdateIndicators)' to reflect the new name.

yeah just got that sorted out it was an error on my part, but I still get the lua error on casting

code

semlar 05-14-14 05:56 AM

Alright, get rid of the UpdateIndicators function, leave indicatorPositions and indicatorBackdrop above the Shared function, and change the "if cfg.indicators.enable then" block to this..
Lua Code:
  1. if cfg.indicators.enable then
  2.         local indicators = CreateFrame("Frame", nil ,self)
  3.         indicators:SetAllPoints(true)
  4.         indicators:EnableMouse(false)
  5.         self.indicators = indicators
  6.  
  7.         -- Build the indicators
  8.         for i = 1, #indicatorPositions do
  9.                 local position = indicatorPositions[i]
  10.                 local indicator = CreateFrame("Frame", nil, indicators)
  11.                 indicator:SetPoint(position)
  12.                 indicator:SetSize(5, 5)
  13.                 indicator:SetBackdrop(indicatorBackdrop)
  14.  
  15.                 indicator.aura = cfg.indicators["aura"..i]
  16.                 indicators[position] = indicator
  17.         end
  18.  
  19.         -- Register the event on the frame itself
  20.         self:RegisterEvent("UNIT_AURA", function(self, event, unit)
  21.             for i = 1, #indicatorPositions do
  22.                 local position = indicatorPositions[i]
  23.                 local indicator = indicators[position]
  24.                 indicator:SetShown(UnitBuff(unit, indicator.aura))
  25.             end
  26.         end)
  27. end
or possibly change "local indicator = indicators[position]" to "local indicator = self.indicators[position]" in your UpdateIndicators function, try that before you replace the whole block of code.

10leej 05-14-14 06:09 AM

1 Attachment(s)
looks like adding the self.indicators did it however they show at all times. Probably because they only have backdrops maybe? Anyways I'm heading to bed got a smallish accomplishment done so thats enough to satisfy me.

semlar 05-14-14 06:25 AM

It looks like the frames aren't hidden by default.

After "local indicator = CreateFrame" add indicator:Hide()

10leej 05-14-14 06:42 AM

Quote:

Originally Posted by semlar (Post 292768)
It looks like the frames aren't hidden by default.

After "local indicator = CreateFrame" add indicator:Hide()

0.0 no wonder. I really should get some sleep.


All times are GMT -6. The time now is 10:29 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI