Monday, April 16, 2012

Hiding a texture, it sounds so easy...

http://pastebin.ca/1197912

I'm currently working on a plugin for oUF to display indicators for missing buffs on party/raid frames (code in pastebin above). Basically, in party/raid frames layout I set this:


Code:
local buffIndicators = {}
table.insert(buffIndicators, {name="Fortitude", colour={1, 1, 1}})
table.insert(buffIndicators, {name="Shadow Protection", colour={.6, .05, .8}})

which is then set as self.IndicatorList and self.IndicatorLayer is an overlay over the whole frame. Basically this an update to oUF_Indicators in that its can work with any class and any number of buffs easily and its something for me to learn Lua with.

The problem I'm having is the textures won't hide when the target is buffed, the print statement in the foreach() loop is executed so the code is making it that far but the texture won't hide and it's driving me up the wall :( I've tried SetAlpha(0), SetVertexColor(1, 1, 1, 0) as well as Hide() just to get rid of it and no go. If I /console reloadui the texture disappears provided the target is buffed and clicking off the buff makes it reappear but I just can't make it disappear when they're buffed.

I'm sure I'm missing something painfully obvious and stupid, if someone could give me a hand with this it would be very much appreciated!

Cheers :)|||I can't see anything obviously wrong. Have you tried hardcoing object.IndicatorObjects[4]:Hide() or similar? The indices look fine but it's all I can think of.|||Ok, directly referencing an indice worked and after some more messing around using k as returned by ipairs() was causing a problem. I'm new to Lua so not sure why but k = tonumber(k) fixed that. I restructured the code a bit which can be seen here and I ran across something interesting.

I added some more helpful debug lines to show which events fired and which parts of the code ran and the way it seems to be working is ipairs() seems to be literally pulling the lists out of object.IndicatorList as once a buff has been handled, the loop doesn't iterate over it again. Here are some screenshots from my chat window in-game showing the messages, they will probably be more help than my attempt at explaination could be ;)





Let me know if you don't understand what I'm getting at and I can edit the screenshots with boxes around the blocks but its fairly easy to see. After I buffed Fortitude object.IndicatoorList[1] (this is Fort in the list) is not iterated over again and the same happens after I buff Shadow Prot.

Any ideas where I'm going wrong, am I looping over object.IndicatorList incorrectly?|||I can't see why that would be happening, the only thing you're calling in :Hide() which shouldn't have any effect on iterating over the table. You might like to try here where a few experiences authors post (it's a great book too).|||http://pastebin.ca/1198702

After a nights sleep I got it, I knew it would be something simple ;)

I was hiding the texture if the buff was present but then because the texture was hidding, the if object.IndicatorObjects[k]:IsShown() then line was evaluating false and so basically voiding the for loop. I added a new function that loops over the IndicatorObjects showing them all and called that at the start of PostUpdateAura() and now it works fine.

Thanks very much for your help Tunga and thanks for the link, the book looks like a fantastic read :)|||Oh, that's actually really obvious now that I look again, I didn't even notice that if-statement. Glad you got it working anyway.

The book is great, I bought it because there's a real lack of mid-level addon coding resources and it filled the void perfectly.

No comments:

Post a Comment