Using "after" rule on "buying" action

If I understand correctly, in Inform 7 “Buy” is defined, but there is no way for it to do anything but print “Nothing is on sale”. I’ve seen some example code and adapted it for my needs. Here it is in case this helps:

Instead of buying something:
	decrease the price of the money by the price of the noun;
	say "You pay [the price of the noun] for [the noun], leaving yourself with [the price of the money].";
	if the money is free:
		now the money is nowhere;
	now the price of the noun is $0.00;
	now the player is carrying the noun.

This is great except I can’t use an “after buying” rule because “buying” fails (since I’m using “Instead of”). I tried to change the code from “instead of buying” to “carry out buying”, but that doesn’t work, simply printing “Nothing is on sale” presumably because I cannot override a built-in command in this way.

What I’m trying to accomplish is:

After buying train ticket:
	try giving train ticket to conductor.

Is there a way to do this? Thanks.

Looks like there’s a special “block buying” role that’s what’s giving you trouble here (you can diagnose this sort of thing by using the ACTIONS and/or RULES testing commands, then seeing how Inform is processing your input). Example 262 in the docs has some guidance here.

So you should be able to either write “The block buying rule does nothing/is not listed in the check buying rules.” then write your own check and carry out rules, or, more elegantly, list your custom-written check rule instead of the block buying rule in the check buying rules.

1 Like

Thanks, I must have missed that.

You can also only conditionally override the standard check rule:

The block buying rule does nothing when the noun is the train ticket.

Or even:

The block buying rule does nothing when the noun is purchasable.

Just depends on whether you want the standard failure message in other circumstances or not.

3 Likes