Problems automatically generating exits

I’m working on a map that automatically generates room connections based on 3D coordinates assigned to each room (you’re allowed to travel to any adjacent room at the same level), and I’ve run into a couple of puzzling problems with this statement:

When play begins: repeat with current room running through rooms: let x be the latitude of the current room; let y be the longitude of the current room; let z be the level of the current room; if y > 1: let n be y - 1; let the north room be a random room with longitude n and latitude x; if the level of the north room is z: now the north room is mapped north of the current room.

The main error I’m getting is that I can’t, apparently, refer to “a random room with longitude n.” Why not? Is my phrasing just wrong, or can I not randomly select a thing by its values?

I’m also getting this error, and I have no idea why:

Help?

This may be tricky.

You can select a thing by a property, but you have to define a sentence verb for it. An unlovely example:

The verb to longit (it longits, they longit, it is longiting) implies the longitude property.

You can then say “a random room that longits N”.

(The verb can be more than one word; I just tried a simple form to test it.)

However, I don’t think you can apply two restrictive clauses in the same description. The only way I see to do it is to fall back to global variables. Set global-n and global-x, and then have

Definition: a room is n-x-correct if the longitude of it is global-n and the latitude of it is global-x.

You can then talk about “a random n-x-correct room”.

The “end if” problem should go away if you indent properly. You code compiled when I fixed the randomizer line.

Definition: a room is n-x-correct if the longitude of it is global-n and the latitude of it is global-x.

Does this work for you? It won’t compile for me if I put a variable in the definition instead of a constant.

(It occurs to me that the less elegant, but eminently more practical, way to do this is to just nest another repeat running through and then use if statements to check each coordinate.)

Yeah, I compiled this last night to test.

A room has a number called the latitude.
A room has a number called the longitude.
A room has a number called the level.

When play begins:
	now global-n is 5;
	now global-x is 6;
	let the north room be a random n-x-correct room.

Global-n is a number that varies.
Global-x is a number that varies.

Definition: a room is n-x-correct if the longitude of it is global-n and the latitude of it is global-x.