I’m trying to have a NPC randomly move between rooms in order to search for the player. The only catch is the NPC is restricted to a specific region.
I’ve got this code:
Dragon Accessable is a region. Denied is a region. TestingCenter is a room in Dragon Accessable. TestingNorth is a room in Dragon Accessable. It is north of TestingCenter. TestingEast is a room in Dragon Accessable. It is east of TestingCenter. TestingSouth is a room in Denied. It is south of TestingCenter. TestingWest is a room in Denied. It is west of TestingCenter. TestingNorth is northwest of TestingEast. TestingEast is northeast of TestingSouth. TestingSouth is southeast of TestingWest. TestingWest is southwest of TestingNorth. [m300/m349]Erdeth is a man in TestingCenter. The description of Erdeth is "The great red dragon Erdeth, grown too large to escape his lair and having eaten everything he can reach, now spends most of his time hibernating and waiting for food to come to him." Before printing the name of Erdeth when looking, say "the great dragon ". Understand "great dragon" or "dragon" as Erdeth. Every turn (this is the hungry dragon rule): If the location of Erdeth is the location of the player: say "[one of]Erdeth snuffles around, trying to find where the delicious scent of food is coming from.[or]Erdeth turns over a nearby rock, hoping to find something - or someone - to eat.[or]Erdeth lashes his tail angrily, narrowly missing your head.[then at random]"; hunt the player; Otherwise: hunt the player. To hunt the player: let origin be the location of Erdeth; let nextspace be a random room in Dragon Accessable which is adjacent to origin; let way be the best route from the origin to nextspace; say "debug - origin is [origin]."; say "debug - nextspace is [nextspace]."; say "debug - way is [way]."; If Erdeth is visible: say "With a frustrated whine, Erdeth moves [way], trying to find someone to eat."; try Erdeth going way; If Erdeth is visible: say "Erdeth screams in rage as he spots you!".
It works fine if I take out the ‘in Dragon Accessable’ bit in the hunt the player routine… but then the dragon goes wandering into rooms he’s not allowed into. What can I do to make this work properly?
Also I wish Inform had a spellcheck function… I had no idea ‘accessible’ was spelled with an i…