On the advice of the forum, I’ve been trying to stop using INSTEAD OF, BEFORE, and AFTER for most things in favor of CHECK, CARRY OUT, and REPORT. The results have been an extremely mixed bag. Now that I’ve changed a lot of my code, I get all sorts of weird undesirable responses I don’t know how to fix. The current problem involves taking a raygun from someone who can no longer use it.
Check taking the raygun:
if the dead agent carries the raygun:
continue the action.
That seems to belong to the dead agent.
If I replace “continue the action” with “now the player carries the raygun”, I get:
You already have that.
If I use INSTEAD OF TAKING THE RAYGUN, it just works. What am I doing wrong?
You’re running afoul of a built-in rule, the can’t take people’s possessions rule, which is another check taking rule that by default disallows taking other characters’s stuff (you can figure this out by using the RULES testing command and seeing what rule is firing before the weird output - then you can look up the name-checked rule in the Standard Rules; I like @Zed’s website for these purposes).
The reason you’re not having the problem when using an Instead rule is that Instead rules bypass all other relevant rules, so no check taking rules, including the can’t take people’s possessions rule, will fire in that case.
Anyway the fix for this is just to tell Inform that rule doesn’t apply in this case; from what you’ve posted, sounds like something like this might work (not tested since I’m on my phone, sorry!):
The can’t take people’s possessions rule does nothing when the noun is the ray gun and the ray gun is enclosed by the dead agent.
Thanks! I’d actually tried
The can't take people's possessions rule does nothing when taking the raygun from the dead agent.
And that hadn’t worked. I guess I was on the right track, but wording it wrong.
Thanks a million.
Yeah, almost! There’s no “taking it from” action in Inform, was the reason that didn’t work - there is “removing it from”, but that pretty much just redirects to taking so you’re usually better off sticking to writing rules about taking rather than messing about with it.
Note also that if you look up any action under the index tab of the IDE, you will see a list of every rule applied to it, in the order they fire. Next to each rule is an icon that you can click which pastes the name of the rule into your source (this helps to eliminate typos). Next to that is an icon labeled “unlist” which in previous builds of Inform pasted a line of code into your text to unlist that rule completely, but now seems to paste code which allows one to alter the response text of that rule. (This is either a bug or an undocumented/mislabeled feature change. I’ll have to check the bug tracker if someone – ahem – doesn’t beat me to it.)
Something to remember is that the Instead and After rulebooks both stop the action by default, as if they had a last line of
stop the action. The other action rulebooks: Before; Check; Carry out; Report all continue the action by default, as if they had a
continue the action on their last line. So a rule like this::
can’t actually affect anything. It says “under these circumstances, continue the action, but otherwise… continue the action”.
I was one of the boosters of the idea of using Check rules instead of Instead rules where possible, but you shouldn’t expect to get an equivalent effect out of a Check rule that you were getting from an Instead rule with the exact same rule preamble and body: you’ll have to change it.
Edited to emphasize: Though it’s often the case, as here, that you get much more bang for your buck through judicious use of a
rule does nothing when to selectively ignore an existing rule than by making a new one. I couldn’t tell you how many times I’ve been struggled with multiple overcomplicated rules involving some global variable I’d added only to realize that I could get most or all of what I was after with a
rule does nothing when…
I did change my check rules from what the insteads said (which would have included “now the player carries the raygun” instead of “continue the action”). Complicating my communication here is that I do my coding on an old computer because it’s the only one I have that lets me work with multiple monitors and a full keyboard at the same time. My best possible browser on that machine is no longer supported by INTFICTION.ORG, so I can’t copy/paste my actual code examples into the forum anymore (this is a pretty recent thing). I have to move to a different machine and either retype everything, or else e-mail myself the code, copy/paste, and manually re-indent every line. The effect is that I simplify code to death when I post my questions and don’t post any code I don’t think is necessary to get my point across.