View Single Post
08-25-14, 09:02 AM   #9
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Wimpface View Post
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.
Since GetSpecialization() returns nil on a fresh login I have a hard time believing the code posted works on a fresh login for any caster other than a mage, priest, or warlock.

Originally Posted by Wimpface View Post
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.
The reason p3lim's version isn't working for you is that the isCaster variable is being redefined as local in the cbCheck function instead of reused. So basically you have two isCaster variables at two different scopes.

You can trim it down more with:
Code:
local isCaster
local cbCheck = function()
	if playerClass == 'DRUID' then
		isCaster = (GetSpecialization() or 0) % 3 == 1
	elseif playerClass == 'MONK' or playerClass == 'SHAMAN' then
		isCaster = GetSpecialization() == 2
	elseif playerClass == 'PALADIN' then
		isCaster = GetSpecialization() == 1
	else
		isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK'
	end
end
  Reply With Quote