Mapping a room to a direction stored in a variable

Hi there! I’m trying to write something so that, when a player enters a new room, the next room gets randomly picked and then mapped to a random direction. Something like this,

After going to a room for the first time:
say “Exits are: [exit list][line break]”;
let nextroom be a random unvisited room;
say “next room will be [nextroom][line break]”;
let nextexit be a random direction;
say “next exit will be [nextexit][line break]”;
now nextroom is mapped nextexit of the location of the player; [this doesn’t work]
continue the action;

I tried something like,
change nextexit exit of the location of the player to nextroom;

from the thread at Mapping a room based on a table entry

but it doesn’t do what I want, because it lets the player exit the room but doesn’t actually map the connection in a solid way. I’ve also been trying to set up a table or something that would let me do this but not getting anywhere. Is there an example out there that might help?

Thanks for any suggestions!

This is the official way to change a room’s exit. What are you looking for that this doesn’t do?

1 Like

It doesn’t stick - When I go to the 2nd room, I can’t go back.

Aha! I think I got it, you have to do the same for the reverse direction,

After going to a room for the first time:
say “Exits are: [exit list][line break]”;
let nextroom be a random unvisited room;
say “next room will be [nextroom][line break]”;
let nextexit be a random direction (called way);
say “next exit will be [nextexit][line break]”;
change nextexit exit of the location of the player to nextroom;
let reverse be the opposite of the way;
change the reverse exit of nextroom to the location of the player;
continue the action;

But I expect it to work again when I enter the second room, since I’m entering it for the first time, and it does not. At least I can go back to the first room, though!

1 Like

Actually this doesn’t work for even more reasons: The “for the first time” only fires off the first time I go somewhere (not each time I go to a new room.) After going to an unvisited room doesn’t work either, because “unvisited” seems to be toggled to visited before I’d like it to be. I will try another approach with “before going to an unvisited room” and see where I can get.

This works, and fits my requirements of being very simple (and not minding about it making sense as the longer examples with x, y, and z coordinates set out.) I’m putting it here in case anyone else is looking for the minimum viable dungeon crawl generator. Now to populate the dungeon!

After going to a room:
	if there are more than 0 unvisited rooms:
		if the player is in a room for the first time:
			say "Exits are: [exit list][line break]";
			let nextroom be a random unvisited room;
			say "next room will be [nextroom][line break]";
			let nextdir be a random cardinal direction (called way);
			say "next direction will be [nextdir][line break]";
			change nextdir exit of the location of the player to nextroom; 
			let reverse be the opposite of the way;
			change the reverse exit of nextroom to the location of the player;
			continue the action;
	otherwise:
		say "You have reached a dead end.";
1 Like