Most recent "try" phrase

Is there any way to test if a most previous “try action” succeeded? It seems the only test is “we have done action”, and that returns true if it ever was successful during play.

From a technical point of view I’m not sure, but what’s the specific use case for this? Generally the thing you want to do is check whether the change you hoped to observe in the model world has come to pass:

Try taking the apple; 
If the player carries the apple: 
    ...

It’s possible in earlier versions of Inform, not sure about v10. It previously required some hacks involving I6 expansion—an action would translate to TryAction(...), so you could create your own routine named RecordTryAction(...) or whatever, then to record the outcome of trying (X - action): (- Record{X} -).—and that’s very much not supported any more.

This would work except in a case where the player was already carrying the apple from before. That’s really the case I want to address to see if the action succeeded this specific time.

If you test immediately after the action, this should work:

try taking the apple;
if rule succeeded [...]

It’s supposed to be the case that any action that ends prior to reaching its carry out rules fails and any that get as far as their carry out rules succeed. But unless you check each action in the Standard Rules, you’re liable to be wrong some of the time about what is and isn’t a failure.

Some actions whose default responses sound kind of failure-ish (squeeze thing => “You achieve nothing by that.”; consult book about halitosis => “You discover nothing of interest in the book”) are successes. Some things that sound not-especially-failure-ish (think => “What a good idea”; sleep => “You aren’t feeling especially drowsy.”) are failures. And try asking bob to try going north succeeds or fails based on whether the player’s persuasion of Bob succeeded or failed, regardless of whether Bob successfully went north.

If one abused Instead rules to simulate a successful action (a practice that can be seen in numerous examples in the docs), e.g.,

Instead of taking the apple: now the player carries the apple; say "You grab the apple."

that would be a failure despite looking like a success.

Or suppose one wrote:

foo is a rulebook.
foo: rule fails.

after an actor doing anything: abide by the foo rules; continue the action.

One would almost certainly have meant to have written follow the foo rules instead of abide by the foo rules. But if one had written that, it’d now be the case that if rule succeeded would be false for all in-world actions for which the foo rulebook failed (in a less contrived case we’d expect that Foo probably succeeds some of the time). So it’s possible to break the efficacy of if rule succeeded as an “if action succeeded” test.

I talked about this previously where I quoted Zarf:

If you can avoid needing to test for action success, I’d recommend doing so.

3 Likes

This works! Assuming, as you said, action success is consistent with failed action rulebooks which is not always the case (unless the programmer takes attention to this, which is exactly what I’m trying to do here).

I think instead is used a lot because it’s convenient and can apply to multiple actions at the same time. Often I find within my instead rules that it’s sometimes a success and sometimes a failure based on conditions. The way to make action results correct is just to add the phrase:

rule succeeds;

In the clauses that reflect a succeeded action.

In fact, the line I wrote to solve the problem I originally started this post for is:

if rule succeeded, rule succeeds;

which looks funny, but actually accomplishes having an action take place if the tried action succeeded. The example is taking an object that is within a container. The game instead tries to take the container, and if it’s successful then the object is considered taken.

1 Like