Map: how to show newly created exit

Hi guys.

Well, map is drawn when a room is first visited, as per the documentation.

What if I want to create a new exit later? This is not shown when I re-enter the room. How can I make it draw the new exit?


Hello.

First, I'd like to note that the compass will update when a new exit is created, which is not very helpful -- as I am quite certain you want the map itself to show the new exit leading from the room.

To be honest, the map is beyond me in some ways, but here's what (I think) I know:

When play begins, the game.pov object's coordinates or 0, 0, 0 (x, y, and z). Quest checks for exits from a room before entering that room, and the exits are etched into the map and somehow tied to that room's coordinates.

Now, all of the coordinates are saved to a dictionary attribute on the game's POV object: grid_coordinates


In my test game, I have a room called "second room" to the north of "room", and a room called "third room" to the east of "room.

When play begins in the starting room, with only those two exits (one North & one East), this is game.pov.grid_coordinates:

Dictionary: room = Dictionary: x = 0;y = 0;z = 0;grid_isdrawn = True;exit1 = Dictionary: x = 0.5;y = 0;end_x = 0.5;end_y = -1;second room = Dictionary: x = 0;y = -2;z = 0;exit2 = Dictionary: x = 1;y = 0.5;end_x = 2;end_y = 0.5;third room = Dictionary: x = 2;y = 0;z = 0

I'm adding a room called "CREATED room" with my TEST command's script, and this new room lies to the west of the starting room.

I am also naming the newly created exit "to_created_room".

This is the dictionary after entering the newly created room:

Dictionary: room = Dictionary: x = 0;y = 0;z = 0;grid_isdrawn = True;exit1 = Dictionary: x = 0.5;y = 0;end_x = 0.5;end_y = -1;second room = Dictionary: x = 0;y = -2;z = 0;exit2 = Dictionary: x = 1;y = 0.5;end_x = 2;end_y = 0.5;third room = Dictionary: x = 2;y = 0;z = 0;grid_isdrawn = True;exit4 = Dictionary: x = 2;y = 0.5;end_x = 1;end_y = 0.5;to_created_room = Dictionary: x = 0;y = 0.5;end_x = -1;end_y = 0.5;CREATED room = Dictionary: x = -2;y = 0;z = 0;grid_isdrawn = True;from_created_room = Dictionary: x = -1;y = 0.5;end_x = 0;end_y = 0.5

So, maybe we can alter the dictionary in the script that creates the new exit?

TO BE CONTINUED


Also see:

http://docs.textadventures.co.uk/quest/showing_a_map.html#advanced-options

http://docs.textadventures.co.uk/quest/using_dictionaries.html


I'm not sure, but I think

// code to create a new exit goes here

// then…
// (assuming ther "room" variable is the room you just created an exit from)
if (game.gridmap) {
  Grid_CalculateMapCoordinates (room, game.pov)
  Grid_DrawPlayerInRoom (game.pov.parent)
  MergePOVCoordinates
}

I've not tested it, but looking at the code it seems that the grid system will scan a room for new exits every time the player re-enters it. So copying those few lines from OnEnterRoom should do all we need.

I'm not sure if Grid_DrawPlayerInRoom is necessary; it might work fine if you omit that.

MergePOVCoordinates may only be necessary if the newly-connected room has previously been visited but is stored in a different map.

If this doesn't work, it could help to do:

coords = Grid_GetPlayerCoordinateDictionary(game.pov)
if (DictionaryContains (coords, room.name)) {
  dictionary remove (coords, room.name)
}

first. This would remove the data for that room from the map; ensuring that the code above will redraw it as if the player had just entered.

[NB: This removes the room from Quest's set of map data, not the JS map data. So if you used the same method for removing an exit, I think it would still be visible on the map until the next time the map was redrawn. I can't be sure what effect that would have. But I think removing a room and then re-adding it again would be more efficient than duplicating all the code (about four screens full) responsible for drawing an exit on the map]


Ah... another thought. Is your new exit a directional exit, or a nondirectional exit?

Right:
create exit ("north", room1, room2, "northdirection")

Wrong:
create exit ("north", room1, room2)

(The first string "north" is the alias of the exit, which the player can type in things like "go north". The second, "northdirection", is the direction the exit goes in for the purpose of the map and compass)


mrangel, your solution seems to be on the right track.

Removing the room data from the map works when you re-enter it.

Redrawing it on the spot, though, seems to have a problem.


Log in to post a reply.

Support

Forums