Comparing list to one another

Is there an easy way to compare list to one another.

For example:

The Waylaying Tunnels is west of the Rubble Heap.

The Waylaying Tunnels is a room.

The tunnel travel is initially false;

Check going to Waylaying Tunnels:
	If the player is in the Rubble Heap and the debris pile is in the Rubble Heap:
		instead say "The wreckage blocks the way west.";
	Otherwise:
		now the tunnel travel is true;
		continue the action

Check going north in the Waylaying Tunnels:
	if the player is in the Waylaying Tunnels:
		if tunnel travel is true:
			add "North" to playerpathlist;
			instead say "North.";
		Otherwise:
			continue the action
		
Check going south in the Waylaying Tunnels:
	if the player is in the Waylaying Tunnels:
		if tunnel travel is true:
			add "South" to playerpathlist;
			instead say "South.";
		Otherwise:
			continue the action
		
Check going east in the Waylaying Tunnels:
	if the player is in the Waylaying Tunnels:
		if tunnel travel is true:
			add "East" to playerpathlist;
			instead say "East.";
		Otherwise:
			continue the action
		
Check going west in the Waylaying Tunnels:
	if the player is in the Waylaying Tunnels:
		if tunnel travel is true:
			add "West" to playerpathlist;
			instead say "West.";
		Otherwise:
			continue the action

The pathoutlist is a list of texts that varies.
The pathoutlist is initially { "North", "West", "South", "West", "South", "East" }.

The playerpathlist is a list of texts that varies.

So the playerpathlist is added to every time the player moves or attempts to move. What I want to be able to do is check whether the last 6 entries in the sequence in playerpathlist at anytime matches the one in pathoutlist, then the player will leave the room.

Is there any easy or built in function to compare list?

In general, two lists can be compared for identical contents in the same order with

if ListA is ListB...

If it’s only the last six entries that matter for playerpathlist, you might be interested in the built-in truncate... phrases; see WI 21.10 Lengthening or shortening a list.

Also, you might prefer to use a list of directions instead of a list of texts for your two globals, which simplifies things a bit. Importantly, the noun of a going action will be the direction chosen, so you can probably turn all of your rules into a single rule that adds the noun directly.

3 Likes

I am a bit slow in posting, I see! Some sample code:

(I tweaked some other stuff just to make tracking the list comparison easier to read)

The maze is a scene.
The maze begins when the player is in WT for the first time.
The maze ends when the player is in Exit for the first time.

WT is a room.
Exit is a room.

WT is north of WT.
WT is east of WT.
WT is south of WT.
WT is west of WT.

playerpathlist is a list of texts that varies.
pathoutlist is a list of texts that varies.
pathoutlist is initially { "north", "west", "south", "east" }

after going when the maze is happening:
	let t be the printed name of the noun;
	add t to playerpathlist;
	truncate playerpathlist to the last 4 entries;
	if pathoutlist is playerpathlist:
		say "Whew! I thought we'd never make it out!";
		move the player to the exit, without printing a room description;
	continue the action.
		
test me with "
e /
e /
e /
e /
n /
w /
s /
e
"

E: it’s possible to just have a list of actions, i.e

pathoutlist is a list of actions that varies.
pathoutlist is initially { going north, going west, going south, going east }
3 Likes

What are the values allowed for list of directions?
The playerpathlist is a list of directions. is not working for me for some reason.

Try

...list of directions that varies.

as you did for the original list of texts.

Anything defined as a direction should be allowed on that list, i.e. north, northeast, east…(other compass directions)… up, down, inside and outside.

1 Like

Accidently deleted my post but thank you!

Thank you again.
How do I call on the direction the player is going to add it to the list?
I tried a few things but have had no luck yet. =\

Check going anywhere in the Waylaying Tunnels:
	if the player is in the Waylaying Tunnels:
		if tunnel travel is true:
			add the direction the player is going to playerpathlist;
			instead say "[playerpathlist]";
		Otherwise:
			continue the action

In the going action, the direction the player is going is just the noun, so “add the noun to playerpathlist” should work.

1 Like

Thank you. :slight_smile: