Redirecting a verb from one object to another

Apologies if this has been covered somewhere before - it feels like something that probably sees very frequent use - but I can’t find a single example and my efforts at guessing the right phrasing have been fruitless.

I’d like to be able to redirect verbs from one object to another in Inform. I’ve got a few occasions where I have, say, parts of a machine where a unique description is necessary for each part, but most actions could just as easily be applied to the machine as a whole. The ideal would be something along the lines of:

The car engine is in the garage. The description of the car engine is “An assortment of pistons and spark plugs that make the car move.” Instead of smelling the car engine, say “Smells of petrol.” Instead of tasting the car engine, say “Tastes metallic.”
The pistons are part of the car engine. Instead of doing something to the pistons, try doing something to the car engine. Instead of examining the pistons, say “All the pistons seem to be in good shape.”
The spark plugs are part of the car engine. Instead of doing something to the spark plugs, try doing something to the car engine. Instead of examining the spark plugs, say “It seems one of the spark plugs is broken.”

The idea here is that if the player tries smelling or tasting one of the components, they’ll get an appropriate response based on the engine as a whole, but if they try examining it then they’ll get the result for that specific action. I can get something similar working by saying “Instead of doing something with X, say Y” (and then overriding it with an action more specific than “doing something”) but I just can’t seem to make that generic “do something” apply to a different object.

I realise it’s probably possible to get a similar result by making “machine components” a kind of thing and providing a smell/taste/whatever for all machine components, but it doesn’t seem as intuitive to me. Also, I feel as though there are other occasions when I’d like to be able to redirect a verb from one object to another in this way so it would be useful to know in general. Could anybody help me out with the exact phrasing to use?

How about this?

A thing can be undistinguished.

Definition: A thing is redirecting if it is undistinguished and it is part of something.

Before doing something (this is the redirect actions on undistinguished components rule):
	unless examining:
		if the noun is redirecting:
			now the noun is the component parts core of the noun;
		if the second noun is redirecting:
			now the second noun is the component parts core of the second noun.

The car engine is here. The description of the car engine is “An assortment of pistons and spark plugs that make the car move.” Instead of smelling the car engine, say “Smells of petrol.” Instead of tasting the car engine, say “Tastes metallic.”

The pistons are undistinguished part of the car engine. Instead of examining the pistons, say “All the pistons seem to be in good shape.”

The spark plugs are undistinguished part of the car engine. Instead of examining the spark plugs, say “It seems one of the spark plugs is broken.”
1 Like

Thank you! This sort of works, but I’ve just had a go and it seems to be redirecting the verb when one thing is part of another regardless of whether or not it’s identified as undistinguished. That is, if I make the pistons an undistinguished part of the engine, but the engine part of a car, “taste pistons” will result in the player tasting the car, not the engine. (The engine itself can still be tasted directly.)

With Editable Stored Actions, you can do this:

Before doing something with an undistinguished thing:
    let the new action be the current action;
    if the noun is undistinguished:
        change the noun part of the new action to the holder of the noun;
    if the second noun is undistinguished:
        change the second noun part of the new action to the holder of the second noun;
    try the new action instead.

The reason the previous code needs to use “component parts core” is because this rule will only run once per action; once the action has been changed, the Before stage it already past and won’t run again. This code will launch the new action as its own separate thing, so it’ll go through the Before stage again, and potentially go up another level of indirection in the process.

2 Likes

Your example code doesn’t show the car engine as part of something else, so it wasn’t clear that you were trying to handle multi-level object structures.

The recursive approach that Draconis suggests will stop substituting at the first not undistinguishable layer encountered. Since undistinguished is a property, you can change that status dynamically, as you like.

The meaning of holder of is a little ambiguous, so be aware that if you’re changing the incorporation relation between objects at run-time (as you seem to be), you might get unexpected results.

Thank you! This seems like a more-or-less ideal solution.

Sorry! I was trying to keep the example simple and didn’t realise that would make a difference. Also there are a few places in this game where it’s proven useful to opt for this kind of setup: the one I tried this with happened to be bolted onto yet another object, but for others your approach would behave as expected.

I’m afraid I’m not sure what you mean by “changing the incorporation relation between objects at run-time.” Would that be if, say, a thing were detached from whatever it’s initially part of and added to the player’s inventory (possibly making the player the “holder”)?

Yes, that’s an example.

1 Like

Yeah, if you want a more general-purpose model, you could do something like…

Redirection relates various things to one thing (called the redirection target).
The verb to redirect to means the redirection relation.
Definition: a thing is redirecting if it redirects to something.

Before an actor doing something with a redirecting thing:
    let the new action be the current action;
    if the actor is redirecting:
        change the actor part of the new action to the redirection target of the actor;
    if the noun is redirecting:
        change the noun part of the new action to the redirection target of the noun;
    if the second noun is redirecting:
        change the second noun part of the new action to the redirection target of the second noun;
    try the new action instead.

The upcoming version will (supposedly) give us the ability to take the transitive closure of relations, which will make this even easier.

1 Like