Thread Tools Display Modes
07-29-16, 02:23 PM   #1
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
Attempting to get player spec for addon if condition

So I have an UI addon that creates it's own Paladin Holy Power bar.

Since Only Ret pallies have it, logic would dictate that I should only display it to Ret pallies!!
Here's my problem.

I determine the player's class (this part works)
Code:
cfg.playerclass = select(2,UnitClass("player"))
in the holypower portion of the addon...
Code:
if cfg.playerclass == "PALADIN" and self.cfg.holypower.show then
bars.createHolyPowerBar(self)
end
that part works.
however, when I determine the players spec:
Code:
cfg.playerspec = GetSpecialization()
and try to work that into the Holy Power creation conditions:
Code:
if cfg.playerclass == "PALADIN" and cfg.playerspec == "3" then
bars.createHolyPowerBar(self)
end
then it breaks.
No errors.
Just breaks.

If I type the the following into the games chat:
Code:
/script print(GetSpecialization())
I get a result of 1 for Holy, 2 for Prot, 3 for Ret.

I've tried the code with all 3 specs and with the "cfg.playerspec == "3" condition, the holy power bar will not display in any pally spec.
  Reply With Quote
07-29-16, 02:41 PM   #2
syncrow
A Flamescale Wyrmkin
 
syncrow's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 149
Lua Code:
  1. -- Preset you Variable
  2. if GetSpecialization() then
  3.     cfg.playerspec = select(1, GetSpecializationInfo(GetSpecialization()))
  4. end

Lua Code:
  1. -- Query
  2. if cfg.playerclass == "PALADIN" and cfg.playerspec == "70" then
  3.     bars.createHolyPowerBar(self)
  4. end

Note:
  • Be aware to call the preset every time, you change your spec.
  • Here is a list of specIDs
__________________

Last edited by syncrow : 07-29-16 at 03:01 PM.
  Reply With Quote
07-29-16, 03:18 PM   #3
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
Originally Posted by syncrow View Post
Lua Code:
  1. -- Preset you Variable
  2. if GetSpecialization() then
  3.     cfg.playerspec = select(1, GetSpecializationInfo(GetSpecialization()))
  4. end

Lua Code:
  1. -- Query
  2. if cfg.playerclass == "PALADIN" and cfg.playerspec == "70" then
  3.     bars.createHolyPowerBar(self)
  4. end

Note:
  • Be aware to call the preset every time, you change your spec.
  • Here is a list of specIDs
Thank you, I will try this method aswell, though I was able to solve this by forcing it to check
Lua Code:
  1. if (GetSpecialization() == 3) then
  2.  bar:Show()
in the visibility check (that also checks for if the player is in a vehicle).
  Reply With Quote
07-29-16, 07:12 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The problem is that you were comparing to "3", not to 3. String ~= number
__________________
"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
07-29-16, 07:49 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Also, you do not need to use select if the first return is all that interests you.

Both of these are identical in function, by way of example. The second adds an unnecessary function/table lookup.
Code:
local player_name = GetFullName("player")
local player_name = select(1, GetFullName("player"))
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Attempting to get player spec for addon if condition


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