Map Teleportation Errors

I'm using a modified movement script for teleporting the player between areas that turn the map on or off. It normally works just fine, but now and then I get an error. This usually happens when turning the map back on after moving the player through numerous rooms while the map is turned off.

For instance, I turn the map off when moving the player to a game show room that is disconnected from the rest of the map. As the player progresses through the game show, they are moved to different rooms (while keeping the map off). Once they're done with the game show, I return them to the original spot they entered from and turn the map back on.

Here is the error:

Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.

Here is the script:

if (game.mapOn and mapOnOff = 0) {
  from = player.parent
  set (player, "saved_map_for_" + from.name, player.grid_coordinates)
}
if (HasAttribute(player, "saved_map_for_" + to.name)) {
  player.grid_coordinates = GetAttribute(player, "saved_map_for_" + to.name)
}
else {
  player.grid_coordinates = null
}
if (game.mapOn and mapOnOff = 0) {
  JS.ShowGrid (0)
}
else if (game.mapOn and mapOnOff = 1) {
  JS.ShowGrid (180)
}
player.parent = to
JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)

"to" is the room I'm sending the player to. "mapOnOff" is used to turn the map on or off when teleporting the player; I pass in 0 to turn the map off, 1 to turn the map on, and 2 if I'm not turning the map on or off. So, I feel like the problem might be occurring when 2 is used, but I can't see where the issue is.


From Hegemonkhan:

The map/grid can't handle movement between rooms, unless it's adjacent room movement (using Exits), so you'll have to clear/toggle off the map/grid, teleport/warp, and then toggle it back on and/or re-initialize/build it. Also, the map/grid can't handle vertical layers (moving 'up' and 'down'), and needs to thus be rebuilt each time too. Jay has some random map generation libraries (see the libraries and code samples forum board), which might get into how to re-build your map/grid when not using Exits or moving vertically (up/down).

I'm stumped there. I can't see where the error is coming in. Is it in Grid_Redraw?


The error does occur when redrawing the map (it it printed after all the on-room-entry text) but I think that's because something went screwy with the saved map data during the off-map teleports?

For instance:

You wake up safe and sound in your room.

You can go north to your living room.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.

Your code looks correct as far as I can tell.

Are any of the rooms being moved while the player is away? I think that might cause a problem.

Could you temporarily replace the call to Grid_Redraw with a slightly more complex piece of code so we can get some more helpful messages?

foreach (room, AllObjects()) {
  if (Grid_GetRoomBooleanForPlayer(game.pov, room, "grid_isdrawn")) {
    msg ("Redrawing "+GetDisplayAlias(room))
    coords = Grid_GetPlayerCoordinatesForRoom (game.pov, room)
    foreach (coord, coords) {
      msg ("<li>"+coord+": "+DictionaryItem(coords,coord)+"</li>")
    }
    Grid_DrawRoom (room, true, game.pov)
  }
}

(that's just a copy of the Grid_Redraw function, but displaying each room's coordinates before attempting to redraw it - so hopefully the messages should tell us what's wrong with those coordinates)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums