View Single Post
08-25-14, 04:06 AM   #8
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Originally Posted by p3lim View Post
You could also simplify the isCaster check a bit
Lua Code:
  1. local cbCheck = function()
  2.     local _, playerClass = UnitClass('player')
  3.     local spec = GetSpecialization()
  4.  
  5.     local isCaster = false
  6.     if(playerClass == 'DRUID' and (spec == 1 or spec == 4)) then
  7.         isCaster = true
  8.     elseif(playerClass == 'MONK' and spec == 2) then
  9.         isCaster = true
  10.     elseif(playerClass == 'PALADIN' and spec == 1) then
  11.         isCaster = true
  12.     elseif(playerClass == 'SHAMAN' and spec == 2) then
  13.         isCaster = true
  14.     elseif(playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK') then
  15.         isCaster = true
  16.     end
  17. end

Also, you need the events to delay the check, on init the spec is not available yet, and will return nil.
Thanks, looks a lot tidier. Changing to this makes it not work on login, as is apparently expected according to you and Phanx' replies. Keeping it the way I have it works on both login and reload...

Originally Posted by Phanx View Post
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.
That makes sense. I've done this for your first example before, so this is vaguely familiar.

Originally Posted by Phanx View Post
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.
This makes my results seem even weirder, as I took all event handling out of the cbCheck() function and it now works properly, both on login and on reload. Unless I'm grossly misunderstanding, it shouldn't work on login as GetSpecialization() doesn't return anything?


Originally Posted by Phanx View Post
There's nothing in the code you posted that does anything with any castbar, so I can't really help you with that.
Sorry, it was included in the OP and I hadn't changed anything important (apart from appearance, like size etc) so I didn't think to include it again. It now works!

Originally Posted by Phanx View Post
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.
I am using oUF:Factory, is this why it's working correctly despite not waiting for events to trigger the function? I don't know why, but it does work on a fresh login for both my melee Monk and my casters with the way I have it now, but changing to p3lim's check makes it behave the way you describe it, as in it doesn't work anymore.

The only difference is at line 192, the cbCheck() function
This works on a fresh login: https://gist.github.com/ShredL/d785e8761d9736d252d5
This doesn't (p3lim's check): https://gist.github.com/ShredL/f9657dd9c9538a89e9ef

Why does one work and not the other? From what I can see, the only difference is cleaning up the if statements. Printing the first (working) version of isCaster returns the correct value on fresh login and reload while printing the other one returns nil on both login and reload.

I appreciate all the help!

EDIT: This reply was messy, I was changing things around as I was testing new things etc and it got really messy. Summary is that it is working correctly when it apparently shouldn't have (first gist) and it isn't working correctly like it apparently shouldn't when using p3lim's suggestion (second gist).
__________________
All I see is strobe lights blinding me in my hindsight.

Last edited by Wimpface : 08-25-14 at 04:09 AM.
  Reply With Quote