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
I imagine it might look something like this:
every turn :
for every cat:
[get a random nearby room and move to it]
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.
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
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.
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]".
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.
"Cats" by Andrew Lloyd Wubber.
The lounge is a room. "There's a comfy couch here, and the kitchen is to
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.
She returns your gaze haughtily."
Clarice is a cat in the lounge. The description is "Clarice is white and
exceedingly fluffy, and floats around the room like a cloud."
repeat with the current cat running through all cats in the location of
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]. ";
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
move the current cat to the next space;
if the current cat is visible, say "[current cat] arrives from [the
test me with "x cora / x clarice / z / n / z / z / z"
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".
>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.
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.