Thread Tools Display Modes
08-18-08, 06:06 PM   #1
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Yet another API function which doesn't work properly...

On a Level 10 Shaman...

IsSpellInRange("Healing Wave","PLAYER") returns "1"

IsSpellInRange("Lightning Shield","PLAYER") returns nil

The character, of course, has BOTH spells in their spellbook.

I'm getting WAY tired of this **** tbh - I assumed after 3 years that the API would actually WORK PROPERLY - but apparently it works "when it feels like it" at best?

I'm sure those of you who've been doing this for a while are used to this slipshoddy ****ty behaviour and the seemingly SHOCKING quality of their code - but I'm not sure why I should keep spending time on addons when

a) Blizzards API is apparently substandard crap
b) at every patch they change it as they feel like it with NO regard for any of the commonsense rules of software development (consistent parameter order, consistent return values, not making old code FAIL by changing things for no really good reason etc)
c) they are not interested in the opinions of EU developers - as we're locked-out of their UI forum discussion anyway...

You have to wonder...
 
08-18-08, 06:33 PM   #2
LBXZero
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 61
Actually, I believe that is working properly.

It gives 0 if out of range, 1 if in range, and nil if target is invalid.

Last edited by LBXZero : 08-18-08 at 06:37 PM.
 
08-18-08, 06:53 PM   #3
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by LBXZero View Post
Actually, I believe that is working properly.

It gives 0 if out of range, 1 if in range, and nil if target is invalid.
... nil also is returned for spells that are not ranged, like lightning shield (self only)
 
08-18-08, 06:54 PM   #4
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
You might want to check out the SpellHasRange API function, which almost certainly also works properly.
 
08-18-08, 06:55 PM   #5
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by kerrang View Post
You have to wonder...
I do wonder if you're going to apologise when you read the replies.
 
08-18-08, 06:56 PM   #6
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by LBXZero View Post
Actually, I believe that is working properly.

It gives 0 if out of range, 1 if in range, and nil if target is invalid.
and what is invalid about casting Lightning Shield on yourself?

I guess the 'problem' is that Lightning Shield is a self-only spell and so has no 'range' to speak-of - however the unit and spell in my example ARE VALID - returning nil is nonsensical...

ESPECIALLY as there is no way that I've found to determine if a spell is self-only anywa!?

There is FAR too much "ah but you need to" and "yeah but that doesn't work if" going on in this API for my tastes - code of this standard wouldn't get you a job in the local utility companies billing dept
 
08-18-08, 07:00 PM   #7
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by kerrang View Post
ESPECIALLY as there is no way that I've found to determine if a spell is self-only anywa!?
Just because you didn't find it doesn't mean it's not there.

There is FAR too much "ah but you need to" and "yeah but that doesn't work if" going on in this API for my tastes - code of this standard wouldn't get you a job in the local utility companies billing dept
You're just making it worse, this is a complex system, there are complex API's.. Just because you dont understand it doesn't make it wrong.
 
08-18-08, 07:03 PM   #8
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by Iriel View Post
I do wonder if you're going to apologise when you read the replies.
Absolutely not - the quality of the API code I've seen thusfar is appalling - there are FAR FAR too many assumptions made - there are FAR too many 'gotchas' - there are even things which simply don't work properly - things which are contrary to fundamental software development rules etc.

Even when you stand back and realise that the API was written with THEIR UI in mind ONLY - that the ability to develop our own mods is almost entirely down to the sterling and tireless work done by people reverse-engineering the code - you still have to wonder whether they don't have some basic coding standards...

I've worked in IT for a long time and I consider myself something of a 'tinkerer' in that I hack things together from string and sellotape when I need to - so the fact that I'm shocked means someone with a formal grounding in this stuff must be LAUGHING THEIR TITS OFF
 
08-18-08, 07:10 PM   #9
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by Iriel View Post
You're just making it worse, this is a complex system, there are complex API's.. Just because you dont understand it doesn't make it wrong.
This really is NOT a complex system - believe me - and even if it were that is NOT an excuse for API functions which return illogical results...

Let's step back here a second

IsSpellInRange - IS SPELL IN RANGE - why would that return a 'false' value for a spell which WILL cast - which will NOT fail due to a RANGE issue?

That makes NO SENSE...

You do NOT develop a API assuming someone will know that certain conditions will produce 'illogical' results - that's an appalling way to design anything - all functions should produce consistent and logical results for the parameters passed (it makes testing about a MILLION times easier).
 
08-18-08, 07:43 PM   #10
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
lightning shield is a self-buff...it doesn't have a range so it can't be out of range. it makes perfect sense for the function to return nil in that case. and btw, 0 is "true" so if you're checking for not IsSpellInRange, that's not going to work :P
 
08-18-08, 08:00 PM   #11
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
It's returning nil tho - which is FALSE - and I still think that makes no sense - it's a RANGE TEST - it WON'T FAIL.

All I can really take from this is that you people are extremely forgiving of what, in commercial IT, would be code of a quality which would get you sacked - which I guess is commendable, but I'm way too old and wizened for **** like this

I'm no 'net nerd' who criticises people's coding style - believes there are right and wrong ways to write things and that it's my job to educate everyone on this issue - quite the opposite in fact, I find such people intensely irritating.

An API, however, is supposed to offer a consistent and logical interface to your engine/system/whatever - there are some fairly "set in stone" rules about how you create and maintain APIs to ensure you don't break existing code - and there are some common sense rules when you're designing functions like this to avoid people having to guess that seemingly 'true' situations will, in fact, return false because they didn't use one of 20 other functions first.

I have this vision - at this point - of a bunch of bearded hippy types in an office strewn with action figures and Boris Vallejo 'art' - one of them is yelling "Why the hell does IsSpellInRange failing for Lightning Shield" - to which some guy in glasses hidden behind 4 monitors in the far corner intones "because you're testing an obviously self-casting spell which has no range".

At this point, were I the questioner - I'd throw said action figures at the "API Nerd" until he begged me to stop - and then I'd sabotage his chair - and set his litter bin on fire - and spraypaint his glasses and so on and so on...
 
08-18-08, 08:26 PM   #12
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
my point was that the return value that signifies "out of range" is "true", so your contention that the "false" return value is somehow wrong begs the question -- i.e. that "out of range" should be a non-true value, which it isn't. nil doesn't mean it will fail, 0 does. would you prefer that "not applicable" be -1? the string "not-applicable"? or what? nil seems like a perfectly reasonable choice to me.
 
08-18-08, 09:30 PM   #13
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by kerrang View Post
It's returning nil tho - which is FALSE
For the record, nil is not false. Type this into any Lua interpreter:

print(nil == false)

And you will find that the result is "false"

Originally Posted by kerrang View Post
All I can really take from this is that you people are extremely forgiving of what, in commercial IT, would be code of a quality which would get you sacked
That's funny. I thought Blizzard was a commercial company. I guess they're non-profit actually. Makes you wonder how much of a tax break they get on those 10 million subscribers. (As a side note, you might consider this: With 10 million subscribers, and several thousand of them doing nothing but coding, you would think they must be doing something right....)

On a similar note, just because the API does not do what you expect does not make it broken. Similarly, just because it does not do what wowwiki says it will do does not make it broken. Only Blizzard truly knows what each function does. The documentation we see is mostly done through reverse engineering, which, even through the strictest practices, is never 100% correct.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/

Last edited by Shirik : 08-18-08 at 09:32 PM.
 
08-19-08, 07:08 AM   #14
Taffu
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 149
There's nothing illogical or "incorrect" about the results of the API IsSpellInRange. There are three logical evaluation results:

In Range = True
Not In Range = False
Not Applicable = Nil

A spell that has no range defined to it is going to return the third value. That spell has no need to have a range value because it is, in fact, not ranged. The API relates to ranged spells, so technically, you're the one using it incorrectly by querying non-ranged spells with a ranged evaluation API. You're luck you're getting a result at all, and not forcing a crash by using the API incorrectly.

Blizzard doesn't "expect" you to know what spells are ranged and what spells are not. However, they do "assume" that anyone taking the time to create UI AddOns has some understanding of the game and the concept behind the system they're designing their AddOn around. If you expect everything to be spoon-fed to you, then Blizzard would have to spend more time developing a fail-safe API system for "optional" AddOn authors rather than time developing what they're selling, which is a game.

So in recap, it's a RANGE TEST, and it doesn't FAIL because it returns an appropriate result for the data you feed it...that is...a NON-ranged spell.
 
08-19-08, 09:05 AM   #15
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Nil is returned by this API function for a range of conditions however - most of which are 'failures' such as an invalid or non-existant UNIT or SPELL

0 is returned where you have a valid spell and unit but the spellcast would fail as it's out-of-range

1 is returned where you have a valid spell and unit and the spellcast would NOT fail - e.g. the unit is in range of the spell

and then nil is returned if you have a valid UNIT and SPELL but the API 'just knows' that the spell has no range - despite there not seeming to be a way to tell this from the API itself...

I still think that is neither a logical nor a meaningful return value for an API to give in those circumstances...

It's the sort of thing you code when you are coding something 'for yourself only' - not considering the need to offer consistency and clear documentation for others (which is what an API should offer)

It's bad coding and it's a pet hate of mine - it's a sign you're either lazy or lack the logical rigor needed to define an API properly - you leave 'assumptions' in you code because you 'know' about them and it's not a problem to you...

Just my 10p I guess...
 
08-19-08, 09:17 AM   #16
kerrang
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 109
Originally Posted by Shirik View Post
That's funny. I thought Blizzard was a commercial company.
You clearly don't work in IT - or at least not in the "boring but necessary" side of it which I usually refer to as 'commercial IT'

I mentioned it because I once did a research project for a 'commercial IT' consultancy - looking at the programming practices of gaming companies.

They were interested in how they shipped code to platforms where they had no ability to maintain it afterwards (e.g. releasing a game onto consoles) - they wanted to know what they could learn from them (as they generally shipped half-finished CRAP and then charged a fortune to patch it up thereafter!)

It was very interesting - what I discovered were some of the most highly rigourous programming techniques and disciplines I'd ever seen and what was MOST interesting was that they were born of necessity and experience (rather than the largely useless crap they teach in college!).

It was very enlightening - I learned a LOT - hence I'm kinda surprised not to find it in the WoW API.

I know that the US Forums get a lot of support from Blizz (or at least 1 member of Blizz's staff) - I know that some mod developers have submitted code which is now part of the API (as it's commented in the files) - but historically speaking, do you really think Blizzard intended us to write addons in the way that we have - or do you think they assumed we'd move a few things around and that was it?

It's obvious we did more than they intended - hence the secure templates etc. - and we certainly see more support and information than we used to - but I get the feeling that the API is still 'begrudged' to us at times...

That may, if it's true, be ironic - because right now the only reason I'm playing WoW is that I've (mostly) enjoyed developing O-Wheely! and O.B.I. - and I know people who spend more time on their UI than they spend on the GAME
 
08-19-08, 09:57 AM   #17
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by kerrang View Post
and then nil is returned if you have a valid UNIT and SPELL but the API 'just knows' that the spell has no range - despite there not seeming to be a way to tell this from the API itself...
Once again, you fail to realize that your lack of knowledge of the API is the problem, not the API itself.

You can determine this from the SpellHasRange() and SpellCanTargetUnit() functions easily. If you wanted to write your own IsSpellInRange() function then you could certainly modify it to take these into account.

Originally Posted by kerrang View Post
I still think that is neither a logical nor a meaningful return value for an API to give in those circumstances...
And I think it's perfectly logical. And so does Blizzard. Fortunately, your opinion is irrelevant in this situation, because the API isn't changing.

Originally Posted by kerrang View Post
It's bad coding and it's a pet hate of mine - it's a sign you're either lazy or lack the logical rigor needed to define an API properly - you leave 'assumptions' in you code because you 'know' about them and it's not a problem to you...
No, it's a sign that you're being lazy and not finding out what the API actually does. Again, there is no formal documentation on this code. YOUR assumptions are irrelevant. Blizzard makes the API and gets to decide what it does. Not you. Therefore, you aren't the one who gets to decide what is "known" or "assumed" by Blizzard.

On that note, I think that this thread has served its purpose (actually, I think this thread has no purpose whatsoever, but its nothingness has been fufilled). You are going nowhere with your arguments except bashing Blizzard because something didn't do what you expect it to do, and unfortunately you fail to realize that it's not "wrong" just because you say it is. As such it's time to end this thread.

-- Shirik
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
 

WoWInterface » Developer Discussions » General Authoring Discussion » Yet another API function which doesn't work properly...

Thread Tools
Display Modes

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