Grid2

Grid2

9M Downloads

Dynamic deficit color

andre-dsm opened this issue ยท 1 comments

commented

This isn't an issue, more of an implementation question on a change I'm trying to make to your addon.

I've written the following fn into StatusHealth.lua:

function HealthDeficitGetDynamicColor(unit)
    local max_health = UnitHealthMax(unit)
    local health_deficit = max_health - UnitHealth(unit)
    return {r=health_deficit/max_health, g=0, b=0, a=1}
end`

What I'm attempting here is to increase the redness of the health deficit bar as health goes down. To use this I think I can do something like the following, however it looks like this status bar color gets set on init and doesn't allow change.

-- health-deficit status
HealthDeficit.GetColor  = HealthDeficitGetDynamicColor

I know percent changes and thus changes the width of the status but I suppose I'm struggling to understand how color is plumbed through. Any guidance here would be very appreciated :)

commented

You can use the health-current status color to colorize your health-deficit bar. By default the color changes from full green at max health, to yellow at medium health and to full red at zero health. But you can change the full health, medium health, and low health colors to customize the color gradient.

You should never create and return new tables in functions that are executed a lot of times per second, this creates and destroys trillion of new tables, generating a lot of garbage data. Its better to create only one table and return the same table.
And use local functions, creating functions or variables (specially with generic names) on the global scope is dangerous.

local color = { r=0,g=0,b=0,a=1}
local function HealthDeficitGetDynamicColor()
  color.r = whatever
  return color
end