Quantcast how to disable oUF element by conditionals - WoWInterface
Thread Tools Display Modes
01-13-13, 12:42 PM   #1
Coldkil
A Theradrim Guardian
 
Coldkil's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 68
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.
  Reply With Quote
01-13-13, 05:54 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) Post the error.

2) Post your code.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
01-14-13, 02:42 AM   #3
Coldkil
A Theradrim Guardian
 
Coldkil's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 68
my code http://pastebin.com/33fM9ZnA

the error http://pastebin.com/Hmc73Dvi
  Reply With Quote
01-14-13, 03:11 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,696
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.
  Reply With Quote
01-14-13, 07:38 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 01-14-13 at 07:40 PM.
  Reply With Quote
01-15-13, 01:06 AM   #6
Coldkil
A Theradrim Guardian
 
Coldkil's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 68
Thanks a lot! Gonna fix the issue right now.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » how to disable oUF element by conditionals

Thread Tools
Display Modes

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