New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some plotscripting commands return seemingly valid values when they fail #1049
Comments
Comment author: @rversteegen This isn't the only coomand that is affected. The majority of functions |
Comment author: msw188 I'm pretty sure that most of the plotscripting commands would do alright with Hmm, actually maybe NPC reference would be trouble here. Aren't certain NPCs |
Comment author: @rversteegen We planned to return 0 by default (actually, I'll just go throw that in - in a The problem really is that currently it's nearly impossible to tell when you're |
Comment author: @bob-the-hamster Just an idea on this subject. What about taking an idea from moldy old DOS batch files? There they have an ERRORLEVEL that gets set after each command. Suppose we had a command like "was error" which woyld return true if the previous command failed, and false if the previous command worked? Not as slick as a try/except/finally block, but a heck of a lot easier to implement :) |
Comment author: @rversteegen You know... if you want try/catch/finally, that could be done ;) Except I've never used exceptions in my life. |
Comment author: @sorlok
I was browsing bugzilla (like you do...) and I came across this bug. If you're considering DOS error levels, you might want to consider Win32's approach too:
I like this approach, because it allows simple error checking via comparison (e.g., some_func() != -1), yet it also permits fine-grained detail when required. Having some wasError() function will clutter scripts a lot more than this. By the way, regarding try/catch/finally; although I use Exceptions constantly in my programming, I tend to agree that they're not really the right way to do things in HSpeak. It just doesn't feel natural, in my opinion. All the best, |
Comment author: @rversteegen Having given this a few years of thought, I don't like either exception handling or errorlevels/GetLastError/WasError. APIs usually suffer from horrible external uncertainties. Did another process just delete this file? Is the system shutting down? Did your dog just chew through the ethernet cable? Compare to plotscripting: there are basically no uncertainties that you can't explicitly check for. You get test whether an NPC exists before calling NPC Y. You can check that a hero is in the intended party slot (really need slot-specific locking though). Or that a slice handle is still valid. One exception might be the joystick commands: we don't have a way to check whether the player unplugged their joystick in the middle of the game or anything like that (not that you would want to bother going to that trouble). Having command-specific failure codes (either 0 or -1 in all cases I can think of) is OK - that's where we're already. Any command that can fail should (implicitly in the case of valid arguments) document all the ways that it can fail, and how to test for them. If a command can return anything as valid data, and can fail, then we need to have to way to check for failure (normally before running the command, so that we can raise a script error). When types are added, we could return special error objects from commands. Some could be distinguishable from all integers (wouldn't do this for any existing commands for compatibility), others could automatically cast to an integer like 0 or -1 (basically the "weak types" I've currently described on the wiki, which I will replace with "objects with an automatic cast-to-int"). They would be recognisable with a "failure" function/predicate (and we could put extra info in them if do we decide that's needed). |
I'm closing this, because there's no specific problem mentioned. The original bug was that A lot of commands (fewer than 15 years ago) have poor error checking, but they're not failing, they're doing something, and that's a different problem. Having given this another decade of thought, I still like the idea of returning "weak types" from a lot of commands: objects that convert implicitly into integers, but can also store extra information like success/failure. Eg |
[bz#36]
The command NPC Y(#) will return the ID number of the NPC referenced if no
copies of that NPC exist on the given map. It should return a value of -1 to
indicate that there are none of the referenced NPCs.
From: Mike Willis <msw188>
Reported version: 20040628 Ozarks
Operating system: Windows ME
The text was updated successfully, but these errors were encountered: