Thread Tools Display Modes
05-24-13, 07:24 PM   #21
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Aanson View Post
Yeah true, you could always contain the data in local UpValues.

It makes little difference though because you'd still need to be constantly updating the value of your UpValues anyway.

Hooking to OnValueChanged just seems like the cleanest way to me. ie.

Lua Code:
  1. myHealthBar:SetScript("OnValueChanged", function(self, health)
  2.     local _, maxHealth = self:GetMinMaxValues();
  3.     healthText:SetFormattedText("%d/%d", health, maxHealth);
  4.     -- update other things here too
  5. end);
This is still more expensive. You're calling the functions in OnUpdate regardless. It's better to save the values to apply them to whatever requires the data than using more function calls (and you're creating variables anyhow in that snippet ).
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-24-13, 08:07 PM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Aanson View Post
Lua Code:
  1. myHealthBar:SetScript("OnValueChanged", function(self, health)
  2.     local _, maxHealth = self:GetMinMaxValues();
  3.     healthText:SetFormattedText("%d/%d", health, maxHealth);
  4.     -- update other things here too
  5. end);
Why on earth would you do that, instead of just update the health text in the same place you're already updating the statusbar value? Hooking your own code -- especially hooking functions in the same file where they are defined in the first place -- is never "clean" or efficient. >_<

Code:
function myAddon:UNIT_HEALTH(unit)
    local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)

    myHealthBar:SetMinMaxValues(0, maxHealth)
    myHealthBar:SetValue(health)

    healthText:SetFormattedText("%d/%d", health, maxHealth)

    -- update other things here too
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-27-13, 03:53 PM   #23
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Miss-read. I thought the bars were already defined in another addon and the op had created another addon to add enhancements to it. Apologies to the o/p.

Phanx, next time you say anything to me in these forums, lose the hormonal attitude please. I've already said this to you before, but I'm starting to think that you enjoy talking to people in the why in which you do.

ElitestJerks is that way >>>>
__________________
__________________
  Reply With Quote
05-27-13, 05:50 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Aanson View Post
... lose the hormonal attitude please.
Because if a woman is short with you, it must be HORMONES, right?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » FontString for value and percent?

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