try silently even if the action fails?

Hi

Is there a way to do a “try silently” that also suppresses output when the action is not successful?

Alternatively: is there some other way of predicting whether a thing can be picked up? Something like “if the noun can be taken by the player”?

My problem is I’m getting “You can’t reach into whatever room the thing is in” messages when I do a “try taking” - also “silently try taking” - and to avoid that I first need to check whether the thing “can be touched by the player”.

My best code bet yet is something like this (entirely contrived) example:

before enchanting:
	if the player is not holding a wand:
		let W be a random wand which can be touched by the player;
		if W is not nothing:
			say "(first taking [W])";
			silently try taking W;
		if the player is [still] not holding a wand:
			say "You'll need to be holding a wand to enchant something. ";
			stop the action.

I guess it works but it feels like a workaround. Maybe I should be using some completely different approach, using a “preferably held” action somehow? But I don’t want the player having to type “enchant frog with the cherrywood wand”, i just want to have her typing “enchant frog”. The player character should just have to have access to a wand.

It’s not actually a wand in my game. Or a frog. Or enchanting.

Distributing the functionality over a couple of rules may perhaps feel more Informish:

[code]Before enchanting when the player does not carry a wand:
if a touchable wand (called an instrument) is in the location:
say “(first taking [the instrument])”;
silently try taking the instrument.
[This will always choose the same wand, I think;
presumably the earliest fitting one defined in source text]

Check enchanting:
if the player does not carry a wand:
say “You’ll need to be holding a wand to enchant something.”;
stop the action.

Report enchanting: say “Xyzzy! You enchant [the noun].”[/code]

No. “try silently” doesn’t interfere directly with any “say” statements. It just stops the action before it gets to the report phase. A curious side effect of this is that “try silently looking” is not silent at all, because looking produces output during the carry out phase!

One possible solution is to use Jesse McGrew’s “Hypothetical Questions” extension, although that may be overkill. I have at the back of my mind an idea to create a whole new system of action processing that makes use of Ron Newcomb’s “Unsuccessful PC Attempt” to separate actions from the messages they produce.

Many actions in Inform (such as going) use action variables to decide what will happen in advance, so the carry out and report phases (and sometimes the check phase) can be properly synchronized. I think it’s a good approach when it’s available, although it might not be the best one in this case.

You can use a [something preferably held] token without forcing the player to type “…with the oak wand” or whatever.

[code]Testing Chamber is a room.

A wand is a kind of thing.

The glass box is a closed openable transparent container, here.
The walnut wand is a wand in glass box.
The top hat is a wearable in Testing Chamber.

The ash wand is a wand, here.

Enchanting it with is an action applying to one visible thing and one carried thing. Understand “enchant [something] with [something preferably held]” as enchanting it with.

Does the player mean enchanting something with a wand: it is very likely.

Before enchanting with:
if the second noun is a wand:
continue the action;
otherwise:
say “[The second noun] has no magick in it.” instead.

Carry out enchanting with:
say “Xyzzy! You enchant [the noun].”

test me with “enchant hat / enchant hat with walnut / enchant hat with hat”.[/code]

The output will look like this…

This way gives the player the option of using “with” or not using it. Also if there are different wands with different effects, you will need to let the player specify which wand anyway.

Wow, thanks a lot. Especially that last bit from Trojo is excellent. Will try!

Followup: Is there any particular logic behind when you refer to an action as “enchanting it with” or “enchanting with” (without the “it”)?

Assuming my action is defined as

Enchanting it with is an action applying to one visible thing and one carried thing. Understand "enchant [something] with [something preferably held]" as enchanting it with.

I seem to be able to use both carry out enchanting with and carry out enchanting it with, but I can only do before enchanting with and not before enchanting it with.

Is that ambiguity on “carry out … with” vs “carry out … it with” something to watch out for, does it matter which I use?

It seems you can also use “enchanting something with something” or even “enchanting something (called the target) with something (called the tool)”.

The common action rules (before, instead, check, carry out, after, report) divide into to groups: each action has its own check, carry out, and report rulebooks (meant for default behaviour of actions); but all actions share the same before, instead, and after rulebooks (meant for exceptions to the defaults).

It seems that the three default action rulebooks all allow these 5 ways of naming an action with two nouns:
Check/Carry out/Report fooing something with something
Check/Carry out/Report fooing with something
Check/Carry out/Report fooing something with
Check/Carry out/Report fooing with
Check/Carry out/Report fooing it with

And – the rules seem to be sorted in that order. (I.e. rules for fooing with something rules are considered earlier than rules for fooing something with, etc.)

The Standard Rules use the “fooing something with” syntax. (That can be good to know.)

The three exception action rulebooks apparently only allow 4 ways of naming an action with two nouns:
Check/Carry out/Report fooing something with something
Check/Carry out/Report fooing with something
Check/Carry out/Report fooing something with
Check/Carry out/Report fooing with

Again – rules seem to be sorted in that order.

You can also write rules for that action that go off of properties, e.g. “enchanting a wearable with”, or kinds, e.g. “enchanting a wand with”, or specific nouns, e.g. “enchanting the top hat with”, or really specific combinations of whatever, e.g…

Instead of enchanting an overcharged wand with the overcharged ash wand when the player is inebriated during Climactic Final Battle: say "You cross the streams! Pow!"; end the story finally saying "You saved the day. Go, you!".
I think the “it” is a keyword that tells Inform that a direct object is supposed to go there in the player’s input. Or something like that. You’ll want to include the “it” in the initial declaration of the action and any Understand phrases, and it doesn’t hurt anything if you leave “it” in elsewhere in place of “something” when writing rules, though you’ll need to replace “it” when writing the rule for something more specific than “something”. At least that’s my understanding of how that works, which is probably wrong or at least over-simplified, but thinking of it that way usually at least results in functioning code for me.

“fooing it with” is part of the actual rulebook name. I think what’s going on is this:

carry out [action description]fooing something with[/action description] [rulebook name implied /] carry out [no action descripton /] [rulebook name]fooing it with[/rulebook name]

You can see the rulebook name in action if you try something like this:

[code]Carry out unlocking something with (this is the extra unlocking rule):
do nothing.

The extra unlocking rule is listed first in the carry out unlocking rulebook. [wrong rulebook name - does not compile]
The extra unlocking rule is listed first in the carry out unlocking something with rulebook. [wrong rulebook name - does not compile]
The extra unlocking rule is listed first in the carry out unlocking it with rulebook. [right rulebook name - works as expected][/code]

Good thinking. That would make sense—i.e. it would explain why you can’t write “carry out fooing it with something” (since that would be a contamination of the name of rulebook with the description of an action) nor “instead of fooing it with” (since the name of the rulebook is just “instead”).
So the upshot is: don’t use “it” when writing a rule; use it when referring to a rule or rulebook. (Don’t use it in rules; use it about rules.)