Noticing an npc for the first time

I have a wandering goat in my game, and I’m trying to figure out how to have it so that when the player is in the same room as the goat for the first time, the goat will be noticed and the game will say something. The following code does not compile. How do I do this?

Goatnoticedness is a kind of value. The goatnoticednesses are noticed and notnoticed. Goat has a goatnoticedness. The goatnoticedness of Goat is usually notnoticed.

When goat is in the location of the player for the first time:
say "There's a goat! That shouldn't be here! It looks like the one your neighbor keeps, but you're not sure.";
now goatnoticedness of goat is noticed.
1 Like

How about an “every turn” rule:

The goat can be noticed or unnoticed. The goat is unnoticed.

Every turn when the goat is visible and the goat is unnoticed:
	say "There's a goat! That shouldn't be here! It looks like the one your neighbor keeps, but you're not sure.";
	now the goat is noticed.

(Addendum: The reason this works, and “when…” doesn’t, is that Inform doesn’t have quite that generic a concept of “when”. Rules are generally tied to a specific action or activity, like “after examining”, or “every turn”. If you think about it, “when such-and-such is true” wouldn’t actually be specific enough, because it doesn’t tell you when in the turn this should happen; whereas “after examining” or “every turn” tie the rule to a specific point in time, giving the game enough information to actually execute it.

In my opinion the Inform documentation isn’t very beginner-friendly in explaining exactly how rules actually work. §12.2 (How actions are processed) is a good starting point. §19 (Rulebooks) is much too technical by contrast, but it’s usually the point where authors have an epiphany about how all of this really works (“Oh! It’s just layers and layers of nested rulebooks that get processed in a specific order, so I need to think about where in that order to put my rules so they interrupt the flow where I need them to.”) [Addendum addendum: Mike beat me to the explanation, ha.]


Couple things! First, the reason this doesn’t compile is that you haven’t told Inform when this rule should run – like, “when the goat is in the location of the player” describes a situation, but it’s not specific enough: should it happen before the player takes their action? Just as the goat takes their action to move? During the end-of-turn cleanup phase? You need what’s called a “rule preamble” set up in order for Inform to understand exactly when the rule should be applied.

That sounds pretty technical, but you’ve probably seen a bunch of examples of these preambles in the documentation – they’re things like “after inserting the foo into the bar” or “every turn when the player is in the lab.” Exactly which one you want to pick probably depends on when you’d like the notification to display; probably an every turn rule is the easiest, but you might want to try that and see how you like the output…

And I just saw that @prevtenet posted an example for what that code could look like, so I’ll stop here!


A few things:

  1. You don’t really need to declare a new kind of value to have a two-state property like that. You can just say The goat can be noticed. and thereafter test or set goat is noticed or got is not noticed.

  2. As prevtenet and DeusIrae explain, the reason that your original code won’t compile is that When goat is in the location of the player for the first time is a condition, i.e. something that evaluates true or false, and conditions are just one of the parts of a “rule preamble,” which is the structure that tells Inform at what point and under what conditions to run code. The every turn rulebook that prevtent suggested is a possible place to set that up.

  3. Another rulebook to consider would be the for writing a paragraph about rulebook. This is automatically checked when printing room descriptions for the player. Some (untested) example code:

	The goat can be noticed.

	Rule for writing a paragraph about the goat:
		if the goat is not noticed:
			say "First description here.";
			now the goat is noticed;
			say "Normal description here."
  1. Unless the noticed state matters elsewhere in your game, you may find that the "[one of]...[stopping]" construction will do this job with the least hassle.

To OP, your case is simple enough that you may not even need a flag.

Whenever the goat’s presence is being mentioned in response to the player moving rooms, Inform will look at the ‘Rule for writing a paragraph about the goat’ that @otistdog mentioned. There is a way to write the description so it says one thing the first time, then a different thing every other time, like so:

Rule for writing a paragraph about the goat:
	say "[one of]There's a goat! That shouldn't be here! It looks like the one your neighbor keeps, but you're not sure.[or]The goat is here.[stopping]";

Now no flag is required. (Though there may be reasons you want one in the future.) There’s more detail about this technique in the docs, 5.7. Text with random alternatives



Thank you! All of this helps a lot.

Did any of it actually solve your problem?


Yes, it solved the problem I mentioned and then another one I hadn’t mentioned XD

1 Like