Local colors from 'RAID_CLASS_COLORS' - WoWInterface
Thread Tools Display Modes
12-19-20, 07:40 AM   #1
A Defias Bandit
Join Date: Nov 2020
Posts: 3
Local colors from 'RAID_CLASS_COLORS'

Trying to update a weakaura thats attempting to color the unit frames based off of this

local colors = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
return colors.r, colors.g, colors.b, 1
not sure what is out of date here.. the function is coloring the frames fine most of the time.. but some times im getting a ton of lua errors from it. unsure why.
  Reply With Quote
12-19-20, 08:40 AM   #2
A Frostmaul Preserver
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 294

   local CLASS = select(2, UnitClass("player"))
   return colors.r, colors.g, colors.b
AddOns: Tim @ WoWInterface
Characters: Hunter, Mage, Priest, Monk, DH,
Battle Tag: Tim#11172
Current PC Setup: PCPartPicker List
  Reply With Quote
12-19-20, 11:26 AM   #3
A Defias Bandit
Join Date: Nov 2020
Posts: 3
So.. it works. but it didnt fix the issue.

i figured out a way to replicate the error though. if im targeting myself and zone into another area it gives me this error
me too!
[11:23] [string "--[==[ Error in 'ShUI - Orb Icon Target Sha..."]:4: attempt to index local 'colors' (a nil value)
[11:23] [string "=[C]"]: in function `xpcall'
[string "@Interface\AddOns\WeakAuras\Animations.lua"]:116: in function <Interface\AddOns\WeakAuras\Animations.lua:15>
This is a weakaura unit frame. its giving me this error for every target frame aura that calls for local colors.
im not sure if this is just happening because im zoning in and had a target when it refreshed the color table.. but there isnt a target to find the class of..
  Reply With Quote
12-19-20, 01:20 PM   #4
A Molten Giant
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 575
It's possible there's a problem with accessing global variables within the aura environment during loading screens. WeakAuras attempts to keep aura environments restricted. You can try collecting the color data in a custom init (initialize), storing it in aura_env, and then just using that.

To use the custom init in an aura, click the Actions tab, check Custom under On Init, then put the following in the box that shows up:

Lua Code:
  1. aura_env.colors = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]

Now in your color function:

Lua Code:
  1. function()
  2.     return aura_env.colors.r, aura_env.colors.g, aura_env.colors.b, 1
  3. end

On Init happens once when the aura loads, which means it'll only load the colors on UI load and every time you close the WeakAuras window. Since the color data is now saved within the aura environment, it's always there for use by the aura.
  Reply With Quote
12-19-20, 09:40 PM   #5
A Defias Bandit
Join Date: Nov 2020
Posts: 3
it really doesnt like that. constant errors when i put that in place of the original.

i think its okay though... the errors only happen once per load so its not going to effect performance at all. ill probably just hide the errors.
  Reply With Quote
12-19-20, 11:15 PM   #6
A Scalebane Royal Guard
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You can default to a class if UnitClass returns nil:
Lua Code:
  1. function()
  2.     local _, class = UnitClass("player")
  3.     local colors = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class or "PRIEST"]
  4.     return colors.r, colors.g, colors.b
  5. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Local colors from 'RAID_CLASS_COLORS'

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