Gridmap Clicking

What is supposed to happen when you tick the box that makes the map "respond to clicks"? I tried that and nothing happened. I wanted to have a great big clickable map with a picture overtop of it that moves when the the player is in any given room. I also want to know how to make the map rooms size change midgame and back again, for instance when the player clicks switch on an object.


What is supposed to happen when you tick the box that makes the map "respond to clicks"?

It calls this core function:

  <function name="GridSquareClick" parameters="x, y">
    // Copy this function into your game to handle grid square clicks
  </function>

Basically, if you create your own function with the same name, it will be called when the player clicks on the map; so you can make it do whatever you want.


I am not an expert, but this code may change room size in midgame

This code changes "room", so if you wanna change "room5", edit the code to room5

room.grid_width = 2
room.grid_length = 3
Grid_Redraw

Pretty interesting to find out map "respond to clicks" actually does something!


What I want to do is move player to the room being called by clicking on the map. When I ticked the box "map should be clickable" and then went into my game and clicked on a room on the map, I had expected to move to that room. I still don't know what to add to make that happen. MoveObject (player,(x,y)) or it could be anything else.


While checking out if Daeun's, your script, will change the size of a room midgame is probably well worth looking into for future games and just knowing, what I wanted to do this time is change the default room size as compared to the size of the map. It is usually preset to 30 and 300. I just wanted to set it at say 200 instead of 30 and bring it down to 30 when the player wants to examine more of the map instead of the details, in order to travel long distances. I want to cover the gridmap with an image, and equip it with clickable movement. I can stand the thought of not changing the size of the map at all and leaving the map to show maybe two rows at a time, or three. I don't know. I haven't written it yet.


I want to cover the gridmap with an image, and equip it with clickable movement

For people trying to solve this, this link may offer some insight
https://textadventures.co.uk/forum/quest/topic/5859/picture-zoom


I wasn't able to change from 300 to 200,
but it seems like I can change from 30 to 60,
not sure how the math works,
but it looks like it is zoomed in for me,
unfortunately the old map still exists, and I do not know the code to remove the old map away from view

firsttime {
  JS.Grid_SetScale (60)
  Grid_Redraw
}
otherwise {
  JS.Grid_SetScale (30)
  Grid_Redraw
}

While checking out if Daeun's, your script, will change the size of a room midgame is probably well worth looking into for future games and just knowing, what I wanted to do this time is change the default room size as compared to the size of the map. It is usually preset to 30 and 300. I just wanted to set it at say 200 instead of 30 and bring it down to 30 when the player wants to examine more of the map instead of the details, in order to travel long distances. I want to cover the gridmap with an image, and equip it with clickable movement. I can stand the thought of not changing the size of the map at all and leaving the map to show maybe two rows at a time, or three. I don't know. I haven't written it yet.

Sounds to me like you want to zoom the map, not resize the rooms. The functions you want are the javascript functions window.gridApi.zoomIn and window.gridApi.setZoom. To call those from Quest, you would refer to them as JS.gridApi.zoomIn and JS.gridApi.setZoom.

  • JS.gridApisetZoom (n) sets the current zoom level to n. I'm not quite sure what units it uses, so you may have to experiment if you want to use it.
  • JS.gridApi.zoomIn (n) multiplies the current zoom level by 1.1n - so zoomIn(4) will allow the player to see about 50% more rooms on the map, and zoomIn(-4) will reverse that.

(It should be noted that the player can also call zoomIn by using their scroll wheel over the map; not sure if there's a way to disable that or not, but if you're tying it to an item you probably don't want to let the player zoom the map manually)


[sorry for the long delay between my two posts; I was on a train but it arrived at the station, and then I had to find somewhere I could get my laptop out before finishing this one… and it's telling me I can't post that here when I go to edit]

What I want to do is move player to the room being called by clicking on the map. When I ticked the box "map should be clickable" and then went into my game and clicked on a room on the map, I had expected to move to that room. I still don't know what to add to make that happen. MoveObject (player,(x,y)) or it could be anything else.

I think that to do that, you'd have to find out which room those coordinates correspond to… which might be challenging because the grid doesn't require whole-number coordinates. It looks like the x and y values you get are the grid coordinates of the mouse, rounded down to the nearest square; so if you have a room or exit whose grid size isn't a whole number, the coordinates you're given might not actually be in the same room as the mouse pointer.

Still, assuming whole numbers are sane, you would want something like:

<function name="FindRoomForCoordinates" parameters="player, x, y" type="object">
  dict = Grid_GetPlayerCoordinateDictionary (player)
  if (not dict = null) {
    foreach (roomname, dict) {
      coords = DictionaryItem (dict, roomname)
      room = GetObject (roomname)
      if (DictionaryContains (coords, "x") and DictionaryContains (coords, "y") and not room = null) {
        roomx = DictionaryItem (coords, "x")
        roomy = DictionaryItem (coords, "y")
        if (x >= roomx and y >= roomy and x <= (roomx+room.grid_width) and y <= (roomy+room.grid_height)) {
          return (room)
        }
      }
    }
  }
  return (null)
</function>

<function name="GridSquareClick" parameters="x, y">
  room = FindRoomForCoordinates(game.pov, x,y)
  if (not room=null) {
    // If there are rooms the player can't teleport to (locked doors or whatever),
    // check for them here
    MoveObject (game.pov, room)
  }
</function>

All off the top of my head, but I think it should be a good start.
Note that this will allow the player to click on any room whose coordinates have been calculated, regardless of whether or not the room is actually visible on the map. If you want to restrict them based on closed doors, you'd need to check that.

An alternative for games with more restricted movement might be something like this:

<function name="FindRoomForCoordinates" parameters="player, x, y" type="object">
  checked = NewObjectList()
  if (HasAttribute (game, "teleport_destinations")) {
    tocheck = game.teleport_destinations
  }
  else {
    tocheck = NewObjectList()
  }
  list add (tocheck, player.parent)
  while (not ListCount (tocheck) = 0) {
    room = ListItem (tocheck, 0)
    list remove (tocheck, room)
    list add (checked, room)
    coords = Grid_GetPlayerCoordinatesForRoom (player, room)
    if (DictionaryContains (coords, "x") and DictionaryContains (coords, "y")) {
      roomx = DictionaryItem (coords, "x")
      roomy = DictionaryItem (coords, "y")
      if (x >= roomx and y >= roomy and x <= (roomx+room.grid_width) and y <= (roomy+room.grid_height)) {
        return (room)
      }
    }
    if (GetBoolean (room, "visited")) {
      foreach (door, FilterByAttribute (AllExits(), "parent", room)) {
        if (HasBoolean (door, "allowteleport")) {
          allowed = door.allowteleport
        }
        else {
          allowed = GetBoolean (door, "visible") and not (GetBoolean (door, "runscript") or GetBoolean (door, "locked"))
        }
        if (allowed and HasObject (door, "to")) {
          if (not (ListContains (checked, door.to) or ListContains (tocheck, door.to))) {
            list add (tocheck, door.to)
          }
        }
      }
    }
  }
  return (null)
</function>

This one should only allow the player to click on rooms which are reachable from the player's current location, only passing through rooms they have already visited and unlocked exits.

Because the most common use for scripts on exits seems to be not allowing the player through without a certain item or something like that, this function counts exits with scripts as if they were locked. If you want to override this, or allow the player to fast travel through locked doors, you can give exits an allowteleport boolean, which overrides the default visible/not-locked/not-script checks. There can also be a list, game.teleport_destinations, for rooms which can be clicked on even if there's no path for the player to walk there from here.

I think that for most text adventures, this version of the function would be more useful; but may take more time to execute; so you can figure out which function would best fit your game.


So, what I could do, if the zoom on scroll is something that can be disabled, is make the room description for each room the full sized picture, have a set of flags or attribute system for more than one size, probably only full size and small, make the map respond to clicks by moving the player nest rooms within rooms and give them all the same alias. Add an object that switches the map to small and also changes the size of the picture, then, on click, move the player and also, on room description, move the picture around beyond the screen, depending on which room the player is in, with room description: read the flag or variable integer, set the flag/ or add or subtract from the variable, clear screen plus switch to the larger picture and reset the map, all with the room description. And add smaller pictures which show up over picture map over the gridmap when objects are dropped in rooms when that room would be visible on the map wherever that particular room centre is at the time. I could make the gridmap background really big, 600 maybe, and leave some room for one or two sentences at a time to show on the screen with links and things.


Log in to post a reply.

Support

Forums