Thread Tools Display Modes
08-13-08, 07:20 PM   #1
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
GetSpellInfo() has me tearing my hair out

I have a button on my Druid's actionbar which returns a spellid of '84'

GetSpellName(84,BOOKTYPE_SPELL) returns "Mangle (Cat)"

So far so good - or so you'd think...

GetSpellInfo("Mangle (Cat)") returns nil however
GetSpellInfo("Feline Grace") works - as does almost every other spell.

Here's the clincher tho

sn=GetSpellName(84,BOOKTYPE_SPELL)
name=GetSpellInfo(sn)
This results in name=nil

name=GetSpellInfo(GetSpellName(84,BOOKTYPE_SPELL))
This results in name="Mangle (Cat)"

WTF is going on here???

I'm assuming some asshat-stupidity related to the ()s!?

I've wasted probably 3 hours of my life chasing this around - and ended up with some horrible horrible code just to work around it.

Anyone got ANY idea what's going on because I'd like a heads-up before I walk into another 'illogical beartrap' like this!
  Reply With Quote
08-13-08, 07:28 PM   #2
Footrot
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 2
Try "Mangle (Cat)()".

The name-based spell lookups have an issue with the (), thinking that the 'rank' should be in there, so fails when it can't find the rank of 'Cat' for the spell/ability 'Mangle'. Compare with "Shadowburn(Rank 1)" for example.
  Reply With Quote
08-13-08, 07:39 PM   #3
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
The situation was that I was putting the GetSpellName() results into a table and then using them later in the GetSpellInfo() call - which was failing for some spells but not for others - cue 2+ hours of debugging...

Would putting a "()" on the end of all names always work/solve this?

Embedding the GetSpellName() into the GetSpellInfo() seems to (for some reason) but I'd like a clearer solutions because I have things like

sn=GetSpellName(id,BOOKTYPE_SPELL)
if sn then
name,rank,etc = GetSpellInfo(GetSpellName(id,BOOKTYPE_SPELL))

which looks kinda mad to the casual eye but it's necessary (because some GetSpellName() calls will fail)
  Reply With Quote
08-13-08, 09:03 PM   #4
LBXZero
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 61
I have two methods for you.

A: Store the full spell name in the table.
Code:
local spellName, subSpellName = GetSpellName(id, BOOKTYPE_SPELL)
if (subSpellName) then
 sn = spellName.."("..subSpellName..")"
else
 sn = spellName
end
You can test if "()" works. If it does work, your code can be...
Code:
local spellName, subSpellName = GetSpellName(id,booktype)
sn = spellName.."("..(subSpellName or "")..")"
B: Use the spell ID

GetSpellInfo() does work with GetSpellInfo(spellID, booktype).

Last edited by LBXZero : 08-13-08 at 09:06 PM.
  Reply With Quote
08-14-08, 10:53 AM   #5
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by LBXZero View Post
B: Use the spell ID

GetSpellInfo() does work with GetSpellInfo(spellID, booktype).
I don't have an example for this right now - but I tried GetSpellInfo(id,BOOKTYPE_SPELL) and saw failures/error messages for some spells so gave up on that.

I'm tempted to leave it as-is - it seems to work for all the spells I've tried thusfar - fingers crossed I guess...
  Reply With Quote
08-14-08, 11:24 AM   #6
VgerAN
A Cyclonian
 
VgerAN's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 40
In case it wasn't clear, the "()" on the end would indicate "maximum rank." "Mangle (Cat)" in macro-speak means the spell "Mangle", rank "Cat", which doesn't exist. To make Mangle work in a macro, you have to use "Mangle (Cat)()", or specify a valid rank in the second pair of parentheses. I think that the suggestion provided is what you'll need.
  Reply With Quote
08-14-08, 11:28 AM   #7
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Code:
GetSpellInfo("Mangle (Cat)()")
This works

But you should probably use spellId, not spellName
  Reply With Quote
08-14-08, 12:35 PM   #8
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by p3lim View Post
Code:
GetSpellInfo("Mangle (Cat)()")
This works

But you should probably use spellId, not spellName
I'm stuck with what I get from actionbuttons - which is a 'spellbook' spellid - which means I have to use GetSpellName() to get something which GetSpellInfo() will 'reliably' work with...

I'll play with GetSpellInfo(id,BOOKTYPE_SPELL) a bit more later, see if I can track down why it didn't work the first time I tried it.

Thanks for all the help
  Reply With Quote
08-14-08, 02:34 PM   #9
LBXZero
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 61
For spell book ids, any ID passed greater than 1024 will cause an error. Also, the second parameter, booktype, must be there. No booktype will cause the look up to search the global spells DB instead of the spell book or pet book lists.

One of the tricks I do for debugging is placing DEFAULT_CHAT_FRAME:AddMessage() before the line that is failing to ensure that the proper parameters are being passed. Sometimes weird events occur.

If the spell ID is still causing troubles, you can try the 2 line code from plan A.
Code:
local spellName, subSpellName = GetSpellName(spellID, booktype)
fullSpellName = spellName.."("..(subSpellName or "")..")"
If subSpellName is nil or "", then it will store spellName().
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » GetSpellInfo() has me tearing my hair out


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