I’m in my third week of learning Inform, and already I have learned so much, but still have a long way to go.
I’ve been playing around with defining named rules, and also Scenes, and it got me thinking about the best method (in general) for globally testing conditions. Which is better? Rules or scenes. I mean, what would be the best way to code the following scenario for example:
If you are wearing the hawaiian shirt and Nancy strolls in, say “Nancy shrieks at the shirt you are wearing!”.
As someone who has a bit of programming experience, my first instinct is just to write the IF statement on it’s own, but I know that Inform won’t let me do that. So what would be the best way to invoke it?
I’m about as advanced as you, but my guess would be that you would want to do this with an “Every turn” rule. You’ll need some way to define “Nancy strolls in,” though. Another thing you could do is fold this into whatever code you’re using to move Nancy into the location, or to print the message telling you that Nancy has moved into the location.
Close, but what it would actually do is that Nancy would never move at all when the player wears the shirt (an instead rule stops the action - literally instead of doing x, do y.) Only if Nancy would be going to the player’s location the message would print (but Nancy would still not move.) It would also not work if it’s the player that moves and not Nancy. Plus you mean “location of” instead of “same room”.
A solution with an every turn rule might be something like this:
Every turn when the location of Nancy is the location of the player and the location of Nancy was not the location of the player:
if the player is wearing the Hawaiian shirt:
say "Nancy shrieks at your shirt."
Yes, it looks horrible but what it does is that it checks if Nancy and the player are in the same location right now (location of Nancy is the location…) but that they were in different rooms last turn (location of Nancy was not the location…) This works regardless of whether it was the player or Nancy who moved, or if they were moved to the same location by some other means. It also prints the message only once, not all the time when Nancy sees the shirt (except when they are separated and then moved into the same room again.)
I’m reading a little bit into your example paragraph. If you are moving Nancy around by making her “try” going actions (as opposed to using “move Nancy to” and “now Nancy is in” statements to move her by brute force), you could say:
After Nancy going to a room:
if the room gone to is the location of the player and the player is wearing the hawaiian shirt, say "Nancy shrieks at the shirt you are wearing!"