Help with terrain attributes

Hi,

I have 650 rooms interconnected like a map. I want to be able to set a terrain attribute for a room so that it has specific properties, water, mountain, desert, forest, ect. I want to be able to change the grid_fill to a specific color water= blue, forest = green, ect. How do i set a "terrain" attribute and have it communicate with the specific room i want?


  1. At game object, interface tab, tick map and drawing grid
  2. Create room2
  3. Link room and room2 together so player can move
  4. at room2, attributes tab, add an attribute 'terrain', give it a string value water
  5. add a turn script, name it communicator, tick enabled when game begins
  6. enter code view of communicator and paste this
if (game.pov.parent.terrain= "water") {
  game.pov.parent.grid_fill = "blue"
}
  1. Go to bottom left corner, click filter, tick show library elements, search redraw
  2. Click copy for Grid_Redraw function
  3. Click filter, untick show library elements
  4. enter code view of communicator and upgrade it
if (game.pov.parent.terrain= "water") {
  game.pov.parent.grid_fill = "blue"
}
Grid_Redraw
  1. Create object magicalseed, go to inventory tab, tick object can be taken
  2. Go to features tab of magicalseed, tick use, go to use tab, at use on its own,
    change action to run script, enter code view and type in
game.pov.parent.terrain = "forest"
  1. Go back to communicator and upgrade it again
if (game.pov.parent.terrain= "water") {
  game.pov.parent.grid_fill = "blue"
}
if (game.pov.parent.terrain= "forest") {
  game.pov.parent.grid_fill = "green"
}
Grid_Redraw
  1. Playtest it, we gave room2 water terrain, so it should be blue automatically,
    when we use the magicalseed, whichever the player is in, that room becomes forest immediately and the room becomes green respectively

Quick demo/ Sample code (Customize according to what you need)
To paste the code

  1. Startup your quest gamebook/textadventure, on the right side of the big play button, you can see a code view button
  2. Copy my code to replace the code in the text box, click code view button again.
  3. Viola, it is done, press play button to test out the game and modify the code to your preference.
<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="test14">
    <gameid>3e197e1d-2fc8-4d76-8ce4-d74c8ce580c5</gameid>
    <version>1.0</version>
    <firstpublished>2024</firstpublished>
    <gridmap />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="north" to="room2">
      <inherit name="northdirection" />
    </exit>
    <object name="magicalseed">
      <inherit name="editor_object" />
      <take />
      <feature_usegive />
      <use type="script">
        game.pov.parent.terrain = "forest"
      </use>
    </object>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <terrain>water</terrain>
    <exit alias="south" to="room">
      <inherit name="southdirection" />
    </exit>
  </object>
  <turnscript name="communicator">
    <enabled />
    <script>
      if (game.pov.parent.terrain= "water") {
        game.pov.parent.grid_fill = "blue"
      }
      if (game.pov.parent.terrain= "forest") {
        game.pov.parent.grid_fill = "green"
      }
      Grid_Redraw
    </script>
  </turnscript>
  <function name="Grid_Redraw">
    foreach (object, AllObjects()) {
      if (Grid_GetRoomBooleanForPlayer(game.pov, object, "grid_isdrawn")) {
        Grid_DrawRoom (object, true, game.pov)
      }
    }
  </function>
</asl>

I have 650 rooms interconnected like a map. I want to be able to set a terrain attribute for a room so that it has specific properties, water, mountain, desert, forest, ect. I want to be able to change the grid_fill to a specific color water= blue, forest = green, ect. How do i set a "terrain" attribute and have it communicate with the specific room i want?

If you want this to change when you change the terrain, the simplest way would be to use a change script. This changes the colour every time the terrain changes.

A script like this in your start script would set the initial colour for all rooms, and then set them up to change automatically if the terrain changes.

foreach (room, AllRooms ()) {
  room.changedterrain => {
    terrains = Split("water;forest;desert")
    colours = Split ("blue;green;yellow")
    if (ListContains (terrains, this.terrain)) {
      i = IndexOf (terrains, this.terrain)
      this.grid_fill = ListItem (colours, i)
    }
  }
  room.changedgrid_fill => {
    if (room.grid_render) {
      Grid_Redraw ()
      Grid_DrawPlayerInRoom (game.pov.parent)
    }
  }
  if (HasString (room, "terrain")) {
    do (room, "changedterrain")
  }
}

Then you can set the room's terrain like any other attribute.


I'm not sure what I'm doing wrong. I placed the code in the game start script and then created the attribute "terrain" in the room attribute's tab. I set the terrain value to string and input the variable "water". When I run the game, there appears to be no change. Did i forget something?


Hmm… I've not used the grid system much. Let me try this out to see what the issue might be…

Ah, I was mixing up details of Quest's map system with a different engine. grid_render records whether a room is currently drawn, not whether it should be hidden from the map. So my script was only setting up the script for rooms which are already drawn.

I'll edit the script above, so that it will work correctly.

(edited now… I don't really understand why it's necessary to redraw the whole grid, but apparently telling it to just redraw one room doesn't work. I need to understand Paper.js better if I'm going to do more with the map)


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

Support

Forums