Map won't save

Hello all! I'm working on a game currently and to keep the map from becoming an absolute mess I'm trying to make a separate area for each of 4 main areas. When the player goes through the exit at the top of the map it should take them to what I currently have titled as "test room 1" and if they go through the exit into "test room 2" it should take them back to the original map. However, it won't recall the originally explored areas of the map.
https://docs.textadventures.co.uk/quest/showing_a_map.html This article said to copy this into a function:

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)

I copied it exactly as shown and the "TeleportTo" function works to teleport the player to the new map properly, but every time the player is teleported between the two areas it forgets their exploration and the map has to be filled out again. What am I doing wrong?


Hello.

First, and not being mean (promise), but, when you post code, it's much easier to read it if you nest it between three back-ticks (```).

Like 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)
```

Anyway, here's my guess without seeing the rest of your code:

Do you change the game's POV to an object other than the player object?

If yes, player.parent always targets the room the actual player object is in.

But, game.pov.parent targets the current object which is being controlled as if it were the player.

Meaning, no matter whether you only use the player object or you use more than one object which can be the player object, you can use game.pov rather than player to target the right thing.

So, if you ever change the game's POV, try this:

from = game.pov.parent
set (game.pov, "saved_map_for_" + from.name, game.pov.grid_coordinates)
if (HasAttribute(game.pov, "saved_map_for_" + to.name)) {
  game.pov.grid_coordinates = GetAttribute(game.pov, "saved_map_for_" + to.name)
}
else {
  game.pov.grid_coordinates = null
}
game.pov.parent = to
JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)

Well, never mind that. I'm silly.

I don't think that could be it, because you said the function does actually "teleport" the player to the appropriate room.

Hmm. . .

Is TeleportTo the only thing in your exit script?


Just taking wild guesses. . .

Do you have a link to your game? If we could see more of the code, we could probably pinpoint the issue.


Sorry it's my first time posting! I'll use that to separate code in the future.
I haven't changed the code at all, I copied it exactly out of that guide page. Is there some change I actually need to make to it to make it work? Like is there some value I'm expected to fill in there that it doesn't mention? I'm very very new with this sort of thing so only the most basic things are in it so far.
And no I don't change any sort of POV, I didn't even know that was possible to be perfectly honest.
Yes for testing purposes the TeleportTo function is the only thing at all in the exit script. I wanted to just test the function so I tried to make it as direct and clean as possible.
Unfortunately I can't share the game at this time. Sorry about that.


Sorry it's my first time posting!

No problem. Most people here are posting for their first time. So, I always try to mention that I'm not being mean when I say such things. :)


I haven't changed the code at all, I copied it exactly out of that guide page. Is there some change I actually need to make to it to make it work?

Well, I'm wanting to look at the rest of your code that concerns the exits and such. (There's no telling what code might be fighting with or overriding some other code.)


Like is there some value I'm expected to fill in there that it doesn't mention?

Probably not.


I'm very very new with this sort of thing so only the most basic things are in it so far.

It's all good.

Still though, there's no telling what other stuff you have in your game which may be butting heads with this particular code.


And no I don't change any sort of POV, I didn't even know that was possible to be perfectly honest.

Awesome. Fewer things to wonder about.


Yes for testing purposes the TeleportTo function is the only thing at all in the exit script. I wanted to just test the function so I tried to make it as direct and clean as possible.

Hmm...

I'm thinking there must be some other code somewhere in the game somewhere that's causing the issue.


Unfortunately I can't share the game at this time. Sorry about that.

Oh, that's cool. Nothing to apologize for.

I only wanted to see it so I could try to help out.

Knowing what I know right now, the only help I can provide is to go make an example game to test out this bit of code myself and see if my example game has the same issue.

I'll come back and post my findings.


Alright thank you so much! I'm very grateful for the help! If I can't get it to work without erasing the map it won't be the end of the world, but I'd really like for it to work if possible. This is my first time messing with any scripts that require the actual code to be typed in, everything else I've just done through the in-platform commands. I really like quest and I'd like to get good at it some day.


Are you teleporting the player back to the same room that they have previously teleported from?


Okay. . .

I made a three room game. I have room, room 2, and odd room.

image


Now, room 2 has an "in" exit, which has a script:

TeleportTo(odd room)

odd room has an "out" exit, which has a script:

TeleportTo(room 2)

...and everything works correctly.

To watch it working, click "Details":

mapschmap1


BUT, if I change it where room 2 teleports the player to odd room, and then I have odd room teleport the player to a room other than room 2, it clears the map.

Click "Details" to watch it happen:

mapschmap2


So, my final guess without seeing the code is that maybe you're not returning the player to the same room they were teleported from.

Hope that helps!


Ha!

mrangel beat me to it, and he didn't have to make an example game to do it! :P


Ahhhhhhh THAT'S the problem. I was teleporting it to a different room! My brain didn't connect it until I was actually looking at it! Let me test it now.


Ahah! That was it. It took a little fiddling with it (It does not like to do it as a "when exiting" command but it worked as an in/out command which is really what I wanted most! Thank you so much for the help.


If you want it to work if you teleport back to a different room in the same area of the map, you could change the script to something like:

if (not DictionaryContains (game.pov.grid_coordinates, to.name)) {
  from = game.pov.parent
  saved_coords = NewList()
  destination_map = null
  if (HasAttribute (game.pov, "saved_maps")) {
    foreach (coords, game.pov.saved_maps) {
      if (not DictionaryContains (coords, from.name)) {
        list add (saved_coords, coords)
      }
      if (DictionaryContains (coords, to.name)) {
        destination_map = coords
      }
    }
  }
  list add (saved_coords, game.pov.grid_coordinates)
  game.pov.saved_maps = saved_coords
  player.grid_coordinates = destination_map
}
game.pov.parent = to
JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)

Off the top of my head, so there could be errors in there. And it's bound to be a little slower, as it's searching all of the saved maps to see if any of them contains the room you're teleporting to; rather than reloading the map that was saved when teleporting out of the same room.


Log in to post a reply.

Support

Forums