WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   how to disable oUF element by conditionals (https://www.wowinterface.com/forums/showthread.php?t=45644)

Coldkil 01-13-13 12:42 PM

how to disable oUF element by conditionals
 
I have never needed to do thios so i never tried - i just need the correct syntax.

Basically i use oUF class icons for everyone but warlocks, since i have made my own script. So, while before 5.1 i just didn't define self.ClassIcons for locks (i called if myclass monk, pala, priest) and everything is working, now i need to include them otherwise the classicons module returns me an error not finding the elements.

I can hide the frames, but this way code would be running twice for the same thing and i want to avoid that. Any help will be appreciated.

Phanx 01-13-13 05:54 PM

1) Post the error.

2) Post your code.

Coldkil 01-14-13 02:42 AM

my code http://pastebin.com/33fM9ZnA

the error http://pastebin.com/Hmc73Dvi

p3lim 01-14-13 03:11 PM

You must either have an old version of oUF, or you modified the file, because that line the error comes from doesn't even exist in the current version.

Phanx 01-14-13 07:38 PM

Get the latest version of oUF from Haste's GitHub repository, by clicking the "ZIP" button here:
https://github.com/haste/ouf

However, you will still get another version of the same error with the current version of oUF, because your code is defining a ClassIcons member for all classes, instead of only defining it if you actually create the frames.

Here is a stripped-down version of your code that should help you see the problem:
Code:

local ClassIcons = {}
if myClass == "MONK" or myClass == "PRIEST" or myClass == "PALADIN"  then
        for index = 1, 5 do
                local Icon = CreateFrame("Frame", "coldCI"..index, self)
                ClassIcons[index] = Icon
        end
end
self.ClassIcons = ClassIcons

As you can see, if the class isn't monk, priest, or paladin, no icons get added to the ClassIcons table, but the table still gets attached to the frame, so oUF sees the element, and tries to handle it, but fails because you didn't add the required internals.

Change your code to something more like this to solve the problem:
Code:

if myClass == "MONK" or myClass == "PRIEST" or myClass == "PALADIN"  then     
        local ClassIcons = {} -- only create this if the class is right
        for index = 1, 5 do
                local Icon = CreateFrame("Frame", "coldCI"..index, self)
                ClassIcons[index] = Icon
        end
        self.ClassIcons = ClassIcons -- only set this if the class is right
end

On a side note, I would recommend not giving global names to each icon, or to any other elements of your frame. You can access them faster by table lookups -- eg. frame.ClassIcons[4] -- without cluttering up the global namespace. If you really think you need globals for some reason, at least give them descriptive names, eg. "oUF_Cold_ClassIcon5" is far better than "coldCI5" because it actually tells the user what the frame is and which addon it belongs to.

Coldkil 01-15-13 01:06 AM

Thanks a lot! Gonna fix the issue right now.


All times are GMT -6. The time now is 02:35 PM.

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