Changing grid_length while playing?

For my game's map, I want all the rooms in a specific area to have exits with a grid_length of 0 between them. The problem is that by looking at the map with this method, you can't see which rooms still have exits that you haven't explored yet. The grid lines are helpful in showing this, but it spoils the visual of a more connected area.

Is there a way to change the value of grid_length while playing? I want to have exits begin with a grid_length value of 1 (to show an exit exists) and then set it to 0 on move. However, setting it to 0 doesn't erase the line from the map because it's already drawn. Is there a way to erase the line or rebuild the map before moving?


This is the current script I have tried, but it doesn't completely work. It'll erase the line but the room you travel to will have an empty space between it and the previous room. It will only redraw the map as desired when a second move is made.

ToDestination.grid_length = 0
JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)
MoveObject (player, Destination)

For instance, THIS will work, but there has to be a more elegant way to do it than duplicating the script? (Player begins game in 'Origin' and then moves to 'Destination'. 'ToDestination' is the exit from Origin to Destination.)

ToDestination.grid_length = 0

JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)
MoveObject (player, Destination)

MoveObject (player, Origin)

JS.Grid_ClearAllLayers ()
Grid_Redraw
Grid_DrawPlayerInRoom (game.pov.parent)
MoveObject (player, Destination)

EDIT: This will actually shift rooms outside of the Origin and Destination toward the opposite direction and destroy the map... So it's still not fully functional.


When you first enter a room, it loops over all of the exits and generates the coordinates for any rooms that don't have any. So removing the extra exit wouldn't change the coordinates of the destination.

The coordinates of adjacent rooms are recalculated automatically when the player enters a room. So your method is moving the player to the destination and back again forces Quest to recalculate the coordinates of the destination room when they re-enter origin. But you really don't need this; you can call Grid_CalculateMapCoordinates manually.

If you're doing this for an exit or a modified go command, you could do something like this:

// adjust the length
ToDestination.grid_length = 0

// adjust the length of the exit in the opposite direction, so that
//   going there doesn't move the origin room to the wrong coordinates
FromDestination = GetExitByLink (Destination, Origin)
if (TypeOf (FromDestination) = "string") {
  FromDestination = GetObject (FromDestination)
  FromDestination.grid_length = 0
}

// move the destination room to its new coordinates
Grid_CalculateMapCoordinates (Origin, game.pov)

// and redraw the grid
JS.Grid_ClearAllLayers ()
Grid_Redraw

// move the player; this adds the new room to the map and draws the player in it
game.pov.parent = Destination

With this code, I still get the issue I mentioned in my second post (the destination room is drawn with an empty space between it and the origin room). Then, when the player moves back to the original room, their marker will be in the empty space.


Where are you putting the code?

I'm trying to work through an example in my head, but it's not easy because I don't have a Windows computer (and I can't debug properly in the web version of Quest).

OK, thinking out loud.

Imagine there's just 2 rooms. Origin is at 0/0/0 and Destination is to the East. So as soon as the player enters it, CalculateMapCoordinates will calculate that the exit between them connects the points 1/0.5/0 and 2/0.5/0. And that Destination is at 2,0,0.

The player moves through the exit. Assuming this script runs before they move; so it's an exit script or similar.
The length of the exit is set to 0.
CalculateMapCoordinates is run for Origin again. This calculates that the exit now connects 1/0.5/0 to 1/0.5/0 (so it's got no length), and Destination is now at 1/0/0.

The map is cleared and redrawn, showing only Origin.

Then the player moves to Destination, which is drawn on the map. We rely on OnEnterRoom to add Destination to the map at the coordinates that have already been calculated.
I can't see any other script that would result in the coordinates being wrong.

I'm going to try this myself, making a quick game just to do this; but it might be easier if there was someone with the desktop editor that I could ask to test things.


I'm using a desktop editor myself. I have this code placed into a function, and then I am calling the function in the desired exit's "Run a script (instead of moving the player automatically)" section. I pass through the names of the origin and destination as parameters.


Considering that repeating the script after moving the player will position the rooms correctly, I think there is something key about actually entering the destination room.


OK… I found the problem.

I was an idiot, and typed the two parameters to Grid_CalculateMapCoordinates the wrong way around.
Have corrected the script in the post above now.

Tested and it works. But, if you have a loop of rooms, any exits you haven't been through yet are still drawn as lines, even if you've been to the rooms on both sides. This means that you get lines across the middle of a room, which is awkward.

I think it shouldn't be too hard to fix that.


Awesome, it seems to work perfectly now! Thank you so much.

I think I understand what's going on in this script, so I should be able to implement a fix for looped rooms.


The looped room fix is a challenge. It makes more sense to do it in the player object's changedparent script (or in the OnEnterRoom function, but I can't modify that on the web version).

This seems to work well:

  if (game.pov = this) {
    if (game.gridmap) {
      needs_redraw = false
      foreach (exit, AllExits()) {
        if (HasInt (exit, "real_grid_length")) {
          real_length = exit.real_grid_length
        }
        else {
          real_length = 0
        }
        shrinkme = false
        if (not exit.grid_length = real_length) {
          if (exit.parent = this.parent) {
            if (HasObject (exit, "to") and Grid_GetRoomBooleanForPlayer(game.pov, exit.to, "grid_isdrawn")) {
              exit.grid_length = real_length
              needs_redraw = true
            }
          }
          else if (exit.to = this.parent and Grid_GetRoomBooleanForPlayer(game.pov, exit.parent, "grid_isdrawn")) {
            exit.grid_length = real_length
            needs_redraw = true
            if (IsDefined ("oldvalue")) {
              if (exit.parent = oldvalue) {
                // this is the exit we just came through
                // We've just reduced its length, so we need to recalculate the coordinates of the *current* room from the previous one
                Grid_CalculateMapCoordinates (oldvalue, game.pov)
              }
            }
          }
        }
      }
      if (needs_redraw) {
        JS.Grid_ClearAllLayers ()
        Grid_Redraw
      }
    }
    if (IsDefined("oldvalue")) {
      OnEnterRoom (oldvalue)
    }
    else {
      OnEnterRoom (null)
    }
    if (game.gridmap) {
      MergePOVCoordinates
    }
  }
  this.hasbeenmoved = true

Bold is the code I added.

It allows an integer attribute real_grid_length on exits, in case you want some exits to be drawn with an actual length; otherwise they get shrunk down to zero.

Note: We don't necessarily need to redraw the grid. By default, rooms are drawn as an opaque white box with a border, so as long as you calculate the coordinates correctly before OnEnterRoom is called, the unwanted exit line will disappear because the room is drawn on top of it. I've crossed those lines out in the code above - you only need them if you have a room whose grid width or height is less than the length of the exits, or if you have transparent rooms. Removing the redraw is a little better because the animation of the player moving into the new room works correctly.

It actually might make more sense to modify the Grid_CalculateMapCoordinates function if you can. You could make it ignore the exit's grid_length when calculating the coordinates for rooms. That way they don't need moving.


Hmm, thank you! I think this could definitely come in handy. I'll have to play around with it and see what works best for my game.


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

Support

Forums