Map Wipes After Teleportation

I have the following Teleport function in my game with two parameters ("to" and "mapOnOff"):

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)

The parameter "to" tells the function where I want to teleport the player to. "mapOnOff" tells the function whether I want to turn the map on or off while teleporting, which I use when teleporting to rooms off the map. "0" turns the map off, "1" turns the map on, and "2" does neither for when I want to keep the same state.

The issue I'm having is that when I pass "2" into mapOnOff, the map will sometimes wipe itself while the map is off. When I turn the map back on, the map is a clean slate and the only visible room is the one the player is standing in. So far, this has NEVER happened when I pass in "2" while the map is on.

What case would allow the map to be wiped like this? I always send the player back to the room the map was turned off in before I turn it back on, so it shouldn't be an issue of misplacement. I feel like this might have something to do with "player.grid_coordinates = null" but I'm not sure how to fix this.


I'm not sure what you're doing here. It looks like you're hiding the map, but not disabling it; although I don't know what the rest of the code with your game.mapOn attribute is doing. In this case, you probably don't want to stop the map updating, or to delete areas from the map.

When you call this function, it saves the current location's map only if (game.mapOn and mapOnOff = 0) - in any other case, all currently-displayed map data will be lost.

I would suggest changing the if statement in the first line to if (HasAttribute (player, "grid_coordinates")) { so that if there is any map data saved (whether it's displayed onscreen or not), it will be saved.


Sorry, I'm using a modified version of the "Save the map, single departure" script here:

https://docs.textadventures.co.uk/quest/showing_a_map.html

The original is this:

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
}
player.parent = to
JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)

It's similar but I've tried to changed it to hide or display the map when teleporting. Sorry, but that's what I meant when I said that I was turning the map on and off. It works except for sometimes in the case I mentioned.

As for game.mapOn, this just says whether the map is actually enabled or disabled. I've let the player turn the map off if they don't want to use it. I've changed this script to also try and account for that.


In that case, I would suggest something like:

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
}
player.parent = to

if (game.mapOn) {
  if (mapOnOff = 0) {
    JS.ShowGrid (0)
  }
  else if (mapOnOff = 1) {
    JS.ShowGrid (180)
  }
  JS.Grid_ClearAllLayers ()
  Grid_Redraw
  Grid_DrawPlayerInRoom (game.pov.parent)
}

So that passing mapOnOff a non-zero value hides the map, but doesn't delete the currently-displayed map data.

However, could still be problematic. I think that if the player uses the command to disable the map, teleports to a room off the map, and enables the map again, they will see a map for an area that wouldn't usually have one. (I don't know if this would be a problem for your game or not).


I had to make some modifications, but the same issue occurs with this script. Passing in "2" can still reset the map.


Are you teleporting back to the same room you left from?


I am. I've been playing around and found something odd, though. I can fix this issue by duplicating the following code and placing it after player.parent = to:

if (HasAttribute(player, "saved_map_for_" + to.name)) {
  player.grid_coordinates = GetAttribute(player, "saved_map_for_" + to.name)
}
else {
  player.grid_coordinates = null
}

I'm not sure if it's the best way to solve this issue but the map is no longer resetting. I found that the map continues to draw even while hidden, and I think that the map was doing something weird when setting player.parent = to. It seems that if I set player.grid_coordinates to the saved map ("saved_map_for_" + to.name) after changing the player's parent, it displays the map as it should be.

I've done some testing and it seems to work how I want it to, but could you foresee anything weird happening because of this?

(By the way, I'm keeping the above chunk of code in both places because deleting the first copy will make the game complain about missing dictionary keys.)


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

Support

Forums