Multiple Traveling Characters Problem

I have an animal who should move room to room randomly each turn and a person who should move along a set path and then stop when the path is complete. For an unknown reason, the animal won’t begin moving room to room until the person has completed it’s path. Can anyone tell me why it won’t work? Here is the relevant portion of my code.

[code]The Dungeon is below the Throne Room. “You are in the dark dungeon under the castle. Above you is the throne room.” The mouse is an animal in the Dungeon.

Every turn:
if the mouse is in a room (called the current space):
let next space be a random room which is adjacent to the current space;
if the mouse is visible, say “You see a mouse scurry into the [the next space].”;
move the mouse to next space;
if the mouse is visible, say “A mouse scurries in from the [the current space].”

The Bedroom is west of the Throne Room. “You are in the bedroom. east of you is the throne room.” The maid is a woman in the Bedroom.

Table of the maid’s Movement
destination
Throne Room
Kitchen
Throne Room
Tower
Throne Room
Bedroom

Every turn when the maid is active:
repeat through the Table of the maid’s Movement:
let last space be the location of the maid;
if the maid can be seen by the player, say “The maid leaves to clean the [the destination entry].”;
move the maid to destination entry;
if the maid can be seen by the player, say “The maid arrives from [the last space].”;
blank out the whole row;
rule succeeds.[/code]

I also have a number of “every turn” conditions, although they don’t seem to effect my problem. The only thing I can think of is that there might be limit on the number of traveling characters in the same room at one time. Is there? I would really appreciate any help.

The problem, I think, is that the code for moving the maid has to end with “rule succeeds” (in order to prevent her from going everywhere in a single turn). This shuts off the “every turn” mechanism. And a rule written as “Every turn when the maid is active” is more specific than “Every turn” rules, so it will run first.

This seems to work:

[code]Every turn:
if the mouse is in a room (called the current space):
let next space be a random room which is adjacent to the current space;
if the mouse is visible, say “You see a mouse scurry into the [the next space].”;
move the mouse to next space;
if the mouse is visible, say “A mouse scurries in from the [the current space].”

Every turn:
if the maid is active:
repeat through the Table of the maid’s Movement:
let last space be the location of the maid;
if the maid can be seen by the player, say “The maid leaves to clean the [the destination entry].”;
move the maid to destination entry;
if the maid can be seen by the player, say “The maid arrives from [the last space].”;
blank out the whole row;
rule succeeds.[/code]

Thank you so much! That works perfectly!

I haven’t tested this, but if you want to interrupt the “repeat through the table of the maid’s movement” loop without using “rule succeeds” (which as Jim points out is the source of the bug), you should be able to use “break” instead. See section 11.12 of the documentation.

[EDIT: I had written something inaccurate here about Jim’s code – it looks like it should work as you have it, but you might want to make sure it’s not messing with any other Every Turn rules.]

Yeah, it will indeed break other every turn rules, if they’re placed in the source after the one with “rule succeeds.” I just tested it.

Looks like “rule succeeds” is a no-no in every turn rules. In this case, because you’re in a repeat through loop, as Matt points out, the solution is to use “break”:

Every turn: if the maid is active: repeat through the Table of the maid's Movement: let last space be the location of the maid; if the maid can be seen by the player, say "The maid leaves to clean the [the destination entry]."; move the maid to destination entry; if the maid can be seen by the player, say "The maid arrives from [the last space]."; blank out the whole row; break.

The “break” serves it’s function very well in my code. The “rule succeeds” didn’t effect any of my other every turn rules, though now it makes a lot more sense. Thank you for your help.

“make no decision” is the standard way to exit a rule without stopping the rulebook - it will work just like “break” in this case, but might be easier to read for some I7 authors.

I could have sworn there was a way to choose the first nonblank row in a table, obviating the need for a loop - but I can’t find it in the documentation.

While looking into this, I (re)discovered that cooper’s original code comes straight from ex. 263 in the documentation. The examples ought to be adaptable (that is, if you drop the code into a larger project they shouldn’t break the every turn rules, even if that doesn’t actually bug the example itself), so I filed a bug report.

Anyway, since the documentation does it that way, I’m a little pessimistic about there being a better way to choose the first non-blank row. You can ask for the number of filled rows in a table, but “choose a filled row” doesn’t seem to compile.