Is there a way in inform to properly handle run-time errors?
I’m using Emily Short’s approaches, and my world map is divided into several non-contiguous areas (home, work, store) that the player is magically transported between when "drive"ing a car.
When the player then tries to GO TO KITCHEN when at the store, I get[code]*** Run-time problem P60: Attempt to set a variable to the wrong kind of object: you wrote ‘now approach-heading is the best route from the location to the noun through visited rooms, using doors’, which sets the value to nothing - but that doesn’t have the kind ‘direction’.
You can’t think how to get there from here.
[/code]I like the “You can’t think how to get there from here.” but is there a way I can make it not show the run time error?
In other words, how do I handle errors gracefully? Having the parser spit out run-time errors during play is not a good way to keep players happy, you know?
The problem is that your code is not taking into account the case in which there is no best route from the location to the noun [etc] – in other words, “the best route” is “nothing,” but “nothing” is not a direction. So slap a conditional in front of it: [pseudocode]if such a route exists, now approach-heading is it. Otherwise, do something else (say the “You can’t get there from here”).[/pseudocode]
Are you using version 3 of Approaches? It sounds to me as though you’ve hit a bug that she corrected in Version 4, as she discusses here. Version 4 looks to be up on the site now.
For the record, what you would need to do if you wanted to fix it yourself would probably be to change the extension code to use a local variable and so you can test to see if the route is a direction before you set approach-heading, as in ex. 230, “The Unexamined Life” (or just search the documentation for “if the way is a direction”).
Hm. I just created a little project with two disconnected rooms, and Approaches version 4 gave the proper result. Can you whittle your code to the smallest thing that produces the bug and post it? Had you changed Approaches at all before you got this error? Are you absolutely sure the game is grabbing the right version (sorry for asking this, but I got a lot of weird results because the wrong version of the Standard Rules kept opening)?
I figured out why my modifications aren’t working:
I have approaches installed, but in this story, I’m using Aaron Reed’s Player Experience Upgrade, which includes ver. 3 of Approaches.
Now that I’ve made my adjustments in the proper extension, it’s working. Here is how I modified it:An approach-finding rule (this is the approach-heading selection rule):
let possible-direction be the best route from the location to the noun through visited rooms, using doors;
if possible-direction is a direction:
now approach-heading is possible-direction;
otherwise:
let possible-direction be the best route from the location to the noun through visited rooms, using even locked doors;
if possible-direction is a direction:
now approach-heading is possible-direction;
otherwise:
say "You can't think how to get there from here.";
rule fails; You’re right, version 4 fixes this. Too bad I wasn’t actually using version 4. Herp derp.