# Inform 7 - Cat is a kind of Animal

7 views

### deps

Sep 6, 2008, 9:51:27 AM9/6/08
to
Hello,

Found out about Inform 7 last night and I love it!

I have, however, a small problem.
In my current test adventure I want to have three cats. Named after my
own cats, naturally.
So, I started with the line

A cat is a kind of animal. It is portable.

Later on I create three cats in a room.
But how would I add some rules to the cat? I want the three cats to
behave equally.

I imagine it might look something like this:

[code]
every turn :
for every cat:
[get a random nearby room and move to it]
[/code]

My problem is with the second line there. How do you loop through all
cats that have been created, without naming them?

Thankful for any help.

/Peter

### Mike

Sep 6, 2008, 10:19:49 AM9/6/08
to

Peter,

You can use the phrase "repeat with X running through cats" to achieve
this. Here is an example, replacing "X" with feline (to have a useful
descriptor):

<code>

A cat is a kind of animal.

The cattery is a room. "This is where the cats start". Three cats are
in the cattery.

The catnip room is north of the cattery.
The litter tray room is south of the cattery.
The mouse room is west of the cattery.

Every turn:
repeat with feline running through cats:
let new place be a random room adjacent to the cattery;
now feline is in new place;
say "A cat is now in [new place][paragraph break]".
</code>

### Jerome West

Sep 6, 2008, 10:28:55 AM9/6/08
to
deps wrote:
> [code]
> every turn :
> for every cat:
> [get a random nearby room and move to it]
> [/code]
>
> My problem is with the second line there. How do you loop through all
> cats that have been created, without naming them?

The phrase you need is "repeat with the current cat running through all
cats". The bit that says "the current cat" can be any identifier you
wish. This assumes you've defined a kind called "cat" of course. Here's
an example that does roughly what you're after.

<code>

"Cats" by Andrew Lloyd Wubber.

The lounge is a room. "There's a comfy couch here, and the kitchen is to
the north."
The kitchen is north of the lounge. "A sparkling white kitchen. A
doorway leads south to the lounge."

A cat is a kind of animal.

Cora is a cat in the lounge. The description is "Cora is black as soot.

Clarice is a cat in the lounge. The description is "Clarice is white and
exceedingly fluffy, and floats around the room like a cloud."

every turn:
repeat with the current cat running through all cats in the location of
the player:
say "[current cat] [one of]miaows plaintively[or]prods you with her
paw[or]swats at a passing fly[or]licks at her fur[at random]. ";

every turn:
repeat with the current cat running through all cats:
if a random chance of 1 in 2 succeeds:
if the current cat is in a room (called the current space):
let next space be a random room which is adjacent to the current space;
if the current cat is visible, say "[current cat] heads to [the next
space].";
move the current cat to the next space;
if the current cat is visible, say "[current cat] arrives from [the
current space]."

test me with "x cora / x clarice / z / n / z / z / z"

</code>

FYI, the "repeat with..." phrase is explained in section 11.9 of the
documentation, and the code for moving characters around comes from
example 71 in the recipe book, "Mistress of Animals".

Jerome

### deps

Sep 7, 2008, 7:43:31 AM9/7/08
to

Thanks a lot Mike and Jerome! This was exactly what I needed to
know. :)

### Gene Wirchenko

Sep 7, 2008, 11:58:37 PM9/7/08
to
deps <dep...@gmail.com> wrote:

>Found out about Inform 7 last night and I love it!
>
>I have, however, a small problem.
>In my current test adventure I want to have three cats. Named after my
>own cats, naturally.
>So, I started with the line
>
>A cat is a kind of animal. It is portable.

^^^^^ ^^^^^^^^^^^^
Fluffy snarls at you, then gouges a chunk of flesh out of your hand.
Perhaps another cat would be friendlier.

[snip]

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.