Running a "when" only on the second turn a player is in the location... kind of

I’m almost certainly coming at this from the wrong angle, but I have a cat who is sort of dynamic and they may or may not be in a location. They may also arrive as the player is in the location doing something. I want the programme to run a check to see if the cat arrives, and if they do, to randomly select one of a set of responses.

I then want the program to randomly choose what the cat is up to while they are in the location. What I don’t want is for the cat to arrive, print the arriving prose and then print what they’re up to and I’m not sure how to do this.

Every turn when Gubbins is not in the location and the location is cataccessible and a random chance of one in two succeeds:
	say "[one of]As if from nowhere Gubbins, your cat, appears meowing quietly and rubbing against you leg[or]You can feel eyes on you and you're sure that somewhere in the shadows Gubbins is watching you[or]Like a herd of tiny, furry elephants, Gubbins charges into view, her tail puffed up like a bottle brush[in random order] .";
	move Gubbins to the location;
	now gubbins is undescribed.
	
Every turn when Gubbins is in the location:
	say "[one of]Gubbins sinuously threads her way between and around your legs glancing up at you from time to time with her amber eyes[or]Gubbins sits in front of you purring[or]Gubbins flops down onto the ground asking for a belly rub[in random order] .";
	now gubbins is undescribed.

What’s going on here is that more-specific rules are evaluated before less-specific ones, so your movement rule, which has more conditions, is firing before the responses rule. You can tell Inform to change that default order, though – try this:

Every turn when Gubbins is not in the location and the location is cataccessible and a random chance of one in two succeeds (this is the Gubbins moving rule):
	say "[one of]As if from nowhere Gubbins, your cat, appears meowing quietly and rubbing against you leg[or]You can feel eyes on you and you're sure that somewhere in the shadows Gubbins is watching you[or]Like a herd of tiny, furry elephants, Gubbins charges into view, her tail puffed up like a bottle brush[in random order] .";
	move Gubbins to the location;
	now gubbins is undescribed.
	
Every turn when Gubbins is in the location (this is the Gubbins idling rule):
	say "[one of]Gubbins sinuously threads her way between and around your legs glancing up at you from time to time with her amber eyes[or]Gubbins sits in front of you purring[or]Gubbins flops down onto the ground asking for a belly rub[in random order] .";
	now gubbins is undescribed.
	
The Gubbins idling rule is listed before the Gubbins moving rule in the every turn rulebook.

That’s perfect @DeusIrae. So much better than all the nonsense I was trying with counting turn manipulations and other assorted gobbledygook.

I have two supplemental questions: I’ve adjusted it slightly so as not to overwhelm the player with the cat’s actions but I’m not sure how to just list the cat as being present on the turns it doesn’t do something from the list.

Every turn when Gubbins is not in the location and the location is cataccessible and a random chance of one in two succeeds (this is the Gubbins moving rule):
	say "[one of]As if from nowhere Gubbins, your cat, appears meowing quietly and rubbing against you leg[or]You can feel eyes on you and you're sure that somewhere in the shadows Gubbins is watching you[or]Like a herd of tiny, furry elephants, Gubbins charges into view, her tail puffed up like a bottle brush[in random order] .";
	move Gubbins to the location;
	now gubbins is undescribed.
	
Every turn when Gubbins is in the location and a random chance of one in two succeeds (this is the Gubbins idling rule):
	say "[one of]Gubbins sinuously threads her way between and around your legs glancing up at you from time to time with her amber eyes[or]Gubbins sits in front of you purring[or]Gubbins flops down onto the ground asking for a belly rub[in random order] .";
	now gubbins is undescribed.
	
The Gubbins idling rule is listed before the Gubbins moving rule in the every turn rulebook.

Can you say a little more about what behavior you’re looking for? Typically objects that aren’t doing anything aren’t re-described every turn, but do you want a line saying something like “You can see Gubbins here” if the random chance of one in two fails? If that’s the case, you could do this:

	If a random chance of one in two succeeds:
		Say "[one of]Gubbins sinuously threads her way between and around your legs glancing up at you from time to time with her amber eyes[or]Gubbins sits in front of you purring[or]Gubbins flops down onto the ground asking for a belly rub[in random order] .";
	Otherwise:
		Say "You see Gubbins here."

This might be related, but FYI once an object is set as undescribed, it stays that way, so there’s no need to do that every turn – you can just say “Gubbins is undescribed” when creating her. But that does mean that when a player enters an area where Gubbins is, or types LOOK, they won’t see Gubbins. This might be what you’re trying to ask, but instead of doing that as an Every Turn rule, it might be easier to just make her described (you could also update a conditional in the descriptions of your rooms with a customized sentence for where Gubbins is and what she’s up to in each area, though in that case you’d want her undescribed to avoid doubling up).

Fair.

Here’s what I’m trying to achieve.

The idea is that when a player is in a location, if Gubbins is not in the location already, she might show up.

If Gubbins shows up, her entrance will be described by the (Gubbins Moving Rule) but not by the idling rule. Additionally I don’t want her to be described again in the general room description when she makes her entrance at the same time the player does e.g. You can see Gubbins here.

When Gubbins is in the location, I want her to “do” something occasionally, which you helped me with (Gubbins idling) but, when she is not doing something I want her to be listed if the player “looks”.

Is that possible?

I think if you make Gubbins described, you should get the behavior you’re after (she won’t be included in the room description if she enters the same turn the player does, because the every turn rulebook is evaluated after the player’s action of moving to a new room and seeing it described is resolved):

The one detail that might not align with what you want is that if the player looks on the same turn that the random chance fires, they’ll see this output:

You can see Gubbins here.

Gubbins flops down onto the ground asking for a belly rub. 

If you don’t like that possibility, you could add a conditional to the idling rule so it says “every turn when Gubbins is in the location and doing something other than looking”, which will make so Gubbins never does one of her idle activities on turns when the player is looking around (note that Inform understands these conditions as 1) Gubbins is in the location, and 2) the player is doing something other than looking).

That’s ideal. I think the double description in that final instance is acceptable.

You’re the best.

Of course, glad to be helpful!

A room can be cataccessible or not-cataccessible.

You probably shouldn’t define the negative adjective like that – what ends up happening is that you get four adjectives: cataccessible, not-cataccessible, not cataccessible, and not not-cataccessible.

So either use a different word (e.g. catinaccessible), or just omit that part so that it only defines cataccessible and not cataccessible.

2 Likes

Ah, good catch – I usually try to do “a foo is either X or Y” which I think avoids that fuzziness (though I could be wrong about that!)

I believe the simplest way is to just enclose “Gubbins” in [brackets] every time it’s printed. Printing the name of anything programmatically like that automatically marks it as mentioned, so the writing a paragraph about and related routines don’t run for it that turn. That should result in the desired behavior; a custom activity message obviates the printing of the initial appearance of, or the default “You can also see” message about, the thing in question (when the room description is printed), but still displays it as normal in cases when the idling rule doesn’t run.

WI 18.24 has more about this.

1 Like