WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Local colors from 'RAID_CLASS_COLORS' (https://www.wowinterface.com/forums/showthread.php?t=58471)

Morale 12-19-20 07:40 AM

Local colors from 'RAID_CLASS_COLORS'
 
Trying to update a weakaura thats attempting to color the unit frames based off of this

Quote:

function()
local colors = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
return colors.r, colors.g, colors.b, 1
end
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.

Tim 12-19-20 08:40 AM

try

Code:

function()
  local CLASS = select(2, UnitClass("player"))
  local colors = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[CLASS] or RAID_CLASS_COLORS[CLASS]
  return colors.r, colors.g, colors.b
end


Morale 12-19-20 11:26 AM

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
Quote:

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..

Kanegasi 12-19-20 01:20 PM

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.

Morale 12-19-20 09:40 PM

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.

Vrul 12-19-20 11:15 PM

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


All times are GMT -6. The time now is 05:16 PM.

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