Throwing an object for a specific results

I want to have it happen where if the player throws a crown at some statues, something will happen. I’m guessing that because ‘throwing’ is already an action in Inform that I’m writing the code wrong/confusing things. Any suggestions?

Throwing the crown is an action applying to one thing.
Understand "throw the [crown]" as Throwing the crown.
Understand "throw [crown]" as throwing the crown.


After throwing the Crown at the Cluster of Statues:
	say "The statues’ faces twist in horror, one screams out, 'Death to tyranny', before they all collapse into piles of useless metal parts. You find that they were guarding a window obscured by a canvas shade.";
	Now the Painted Shade is in the Indiana/Kentucky Underground Railroad;
	now the crown is off-stage.

You don’t need to define the action with “is an action …” and you don’t need to define new “Understand …” lines, since the action is already built in, as you mentioned.
(And usually you would not want to define actions with specific objects like that. Actions are typically defined to be very general, and then you write “Before”/“Instead”/“Check”/etc. rules for specific cases.)

If you look at the Index tab in the IDE, and there under Actions → Alphabetic, you’ll find “throwing it at” in the list. If you click the small magnifying glass icon next to that, you’ll find an explanation how Inform handles this action.

Since Inform doesn’t know what the results of a throwing action should be in a specific game, it will by default recognize the command, but block the action from going through.

Quoting the index:

“To make throwing do something, then, we must either write Instead rules for special circumstances, or else unlist these check rules and write suitable carry out and report rules to pick up the thread.”

What you decide to do is up to the needs of your specific game, and especially what you want the game to respond when the player throws the crown at other things instead of the cluster of statues.

Having said that, your example seems to be exactly the kind of case where you want a one-off exception, so a simple “Instead” rule should be fine:

Instead of throwing the crown at the cluster of statues:
	say "That worked!";
	now the crown is off-stage.
3 Likes

You’re basically on the right track for defining a new action, except … you first need to break the linkage between the “throw” command and the existing throwing action. Probably the easiest way to do this is just to first write:

Understand nothing as throwing.

… which will arrange matters so that no player commands can possibly result in the built-in throwing action. It clears the slate and disconnects that action from every command. You can then create a new action and write your rules for it.

On the other hand, if you don’t want to entirely override the throwing action in every circumstance – probably a good idea, since it makes sense to keep the default response in case the player later types throw the pencil or throw the plate or throw the large truck – you can just write a custom response for the single instance of throwing the crown at the statues. To do that, drop all three of your new-action-defining lines, and write the specific case as an instead rather than an after rule:

Instead of throwing the Crown at the Cluster of Statues:
	say "The statues’ faces twist in horror, one screams out, 'Death to tyranny', before they all collapse into piles of useless metal parts. You find that they were guarding a window obscured by a canvas shade.";
	Now the Painted Shade is in the Indiana/Kentucky Underground Railroad;
	now the crown is off-stage.
1 Like

That fixed it! I’m pretty good at making things more complicated than they need be.

1 Like

That is the programmerly condition.

3 Likes