Let’s say I want to print a custom response when a player takes a certain object, and I want the response to be different depending on where the object was when the player took it.
So, as an example, if the player takes the flower from the vase, I want to print one response, but if the player takes the flower from the floor, I want to print a different response.
What’s the best way to do that? Is there a way to check in the “after” stage where the player just took the flower from, or do I need to set a flag when taking the flower? If I need a flag, what rule would be best to put it in–a carry out rule? (I’m not sure if a new carry out rule would get added on to other carry out rules, or if it would end up taking the place of another rule.)
Though note that “was” only works with constants: this doesn’t work if you want your rule to be more general.
Problem. You wrote ‘Report taking something when the noun was in a thing’: but it is misleading to talk about the noun, the second noun or the person asked to do something in past tenses, because in the past, those were different things and people, or may have been nothing at all. Writing ‘if the noun has been unlocked’ tends not to do what we might hope because the value of ‘noun’ changes every turn. So such conditions are not allowed, although to get around this we can instead write ‘if we have unlocked the noun’, which uses a special mechanism to remember everything which has happened to every object.
Not to fear, though, Inform still has a way to do this!
The Lab is a room. A table is a fixed in place supporter in the lab. A vase is a container on the table. A flower is in the vase. A ball is in the lab.
The taking action has an object called the holder taken from (matched as "from").
Setting action variables for taking: now the holder taken from is the holder of the noun.
Report taking something from a thing (called the holder):
say "You take [the noun] from [the holder].";
rule succeeds.
Lab
You can see a table (on which is a vase (in which is a flower)) and a ball here.
>get flower
You take the flower from the vase.
>get vase
You take the vase from the table.
>get ball
Taken.
The ability to add custom prepositional phrases to actions is not often useful (it’s mostly used to add “to” a room, “from” a room, “by” a vehicle, “with” a pushable thing to the going action), but when it is, it’s really nice.