| |
This has been cross-posted from the EU UI forum
--------------------------------------------------
Hello !
The following post will outline a bug in the CastSpellByName() API function available to the client-side scripting interface.
Background and reasons:
This routine takes in a string-type variable, and will use a parsing pattern to discover spell name and spell rank. It then proceeds to loop through your spellbook, using GetSpellName() for increasing index numbers to discover a match with spell name and rank.
However, there is a bug in the pattern used to strip spell name and rank. It is built assuming that the string consists of a spell name and spell rank in form as of below:
"<spell name>(<spell rank and rank number>)" as in "Immolate(Rank 1)".
For these types of parsings, the function works fine and smooth. The correct spell gets casted if other requirement (reagents, proper target etc) are filled.
However, there are certain spells for certain character classes, such as druid and warlock, for whom this function does not identify all spells correctly. Consider the following example:
/script CastSpellByName("Create Healthstone (Lesser)");
First of, the input string is parsed to result a spell name "Create Healthstone" and rank "Lesser". As the function then iteratest through the spellbook, it will fail to find the spell, because all warlock stone creation spells, when queried with GetSpellName() return values such as "Create Healthstone (Lesser)" and an empty string as rank.
Thus, none of the entries returned by the enumeration match the pattern to look for, and the function fails to find the correct index.
This pattern error affects all and every spell which has a parenthesis in it's name, including, but not limited to, the following:
- Create Healthstone (Minor)
- Create Healthstone (Lesser)
- Create Healthstone (Greater)
- Create Healthstone (Major)
- Create Soulstone (Minor)
- Create Soulstone (Lesser)
- Create Soulstone (Greater)
- Create Soulstone (Major)
- Create Firestone (Lesser)
- Create Firestone (Greater)
- Create Firestone (Major)
- Create Spellstone (Greater)
- Create Spellstone (Major)
- Faerie Fire (Cat)
Suggested fix:
The easiest, quickest solution would be to remove the parsing pattern altogether, and instead take in spell name and spell rank as seperate values, such as the following:
/script CastSpellByName("Immolate", "Rank 1");
This would result in some mods using the API call to cease working, thus the change should be written to the patch log.
Another alternative, albeit a more complex one, would be to match the given string against a fixed list of spell names that should not be parsed, such as the ones I have listed above. If a match is found, the parsing is skipped altogether.
The final alternative, the most difficult one, would be to refine the pattern so that if two words in parenthesis are found in a string, the first one is assumed to belong to the spell name, and the lattern assumed to be the rank. This would change the API calls to:
/script CastSpellByName("Create Healthstone (Lesser)()");
Of course, if only a single parenthesis combo is found, the old (current) system would be used to parse spell name and rank. This change might result in add-ons breaking as well.
In light of all these possibilities, the first one sounds most reliable and secure, and would make it certain that the API function will continue to function in all possible situations.
- Gorak
|