View Single Post
08-25-14, 02:50 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Wimpface View Post
I had no idea function calls were slow, I should probably re-do some of my other addons...
Well, function calls are still effectively instant in terms of human perception, it's just that they're significantly slower than everything else you can do in Lua, such as looking up values in tables. This is why I always suggest doing things like "r, g, b = t[1], t[2], t[3]" instead of "r, g, b = unpack(t)" or "for i = 1, #t do local v = t[i]" instead of "for i, v in ipairs(t)" -- wherever you can achieve the same result without calling a function, you're probably better off doing so.

Originally Posted by Wimpface View Post
... is the reason I don't need to check for events at all because I need to reload anyway for my castbar to change, even if the variable value changes when PLAYER_SPECIALIZATION_CHANGED fires?
Information about spells, talents, etc. is available immediately when you reload the UI because you're only reloading the UI; you're not actually disconnecting and reconnecting from the server. Your character and all information about it remain loaded in the client.

Functions like UnitGUID don't return useful values right away on a fresh login, and most likely GetSpecialization doesn't either. You can easily test this by logging out to the character screen and logging back in, with the following code in the main chunk:

Code:
print("Current spec is:", GetSpecialization())
On an actual login I suspect it will report "nil", though it will report the correct value on a UI reload.

Originally Posted by Wimpface View Post
This is the state my code is in right now, ... The castbar still disappears on reload with this code.
There's nothing in the code you posted that does anything with any castbar, so I can't really help you with that.

Originally Posted by Wimpface View Post
I took events out of it altogether, and just did a function that I call once when the code fires. It now works correctly, but maybe it isn't the best way of doing it? Is this different than running a SetScript on a frame? If not, I have no idea what handler to use as OnEvent seems wasteful. Maybe OnLoad?
It won't work on a fresh login; see above.

OnLoad doesn't fire for frames created in Lua, and doesn't need to, as it's the same as just writing the code directly after the CreateFrame call.

If you're not using oUF:Factory already, I'd recommend you switch to it, as it will delay creating your frames until PLAYER_LOGIN, at which time information about things like your spec should be available, even on a fresh login.
__________________
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