Moving multiple roaming NPCs at once

Having trouble with something that seems simple but apparently isn’t. I’m trying to move multiple people at once every turn without having to write the same code for them all individually. I have something that mostly works - but the code will only move a single roamer at a time - the one top of the list in my code. I can set it to random, so it randomly selects a roamer to move - but I’d like all of them to move simultaneously each turn. I’m thinking it might require use of “Repeat” but I can’t quite figure it out. Here’s the relevant snippet.

A Roamer is a kind of Person.
A Roamer can be Paused.

Every Turn:
	if a Roamer (called Moving_Person) is in a room (called the current space):
		let next space be a random room which is adjacent to the current space; 
		move Moving_Person to next space;
2 Likes

Yeah, you need to use “Repeat” – that’s how Inform does loops. This should work for your purposes, I think:

Every turn:
	Repeat with Moving Person running through Roamers:
		let next space be a random room that is adjacent to the location of the NPC;
		move Moving Person to next space.

(FYI, “move” is an out-of-game command that basically just teleports the character around, so this will be invisible to the player; you might want to add some text reporting what’s happening, or just use the “try a character going a direction” approach, which will take advantage of the built in rules for when a character moves around).

5 Likes

I see a potential trouble: what if the roamers interact to the presence and/or absence of other roamers ? if not designed carefully, one can get out-of order, if not even incorrect, reactions from roamers…

Best regards from Italy,
dott. Piergiorgio.