Help with terrain attributes
SummaCivis
13 Nov 2024, 00:43Hi,
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?
daeun
15 Nov 2024, 16:47- At game object, interface tab, tick
map and drawing grid
- Create room2
- Link room and room2 together so player can move
- at room2, attributes tab, add an attribute 'terrain', give it a string value
water
- add a turn script, name it
communicator
, tick enabled when game begins - enter code view of
communicator
and paste this
if (game.pov.parent.terrain= "water") {
game.pov.parent.grid_fill = "blue"
}
- Go to bottom left corner, click filter, tick show library elements, search
redraw
- Click copy for
Grid_Redraw
function - Click filter, untick show library elements
- enter code view of
communicator
and upgrade it
if (game.pov.parent.terrain= "water") {
game.pov.parent.grid_fill = "blue"
}
Grid_Redraw
- Create object
magicalseed
, go to inventory tab, tickobject can be taken
- Go to features tab of
magicalseed
, tickuse
, go to use tab, atuse on its own
,
change action torun script
, enter code view and type in
game.pov.parent.terrain = "forest"
- 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
- Playtest it, we gave room2 water terrain, so it should be blue automatically,
when weuse
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
- Startup your quest gamebook/textadventure, on the right side of the big play button, you can see a code view button
- Copy my code to replace the code in the text box, click code view button again.
- 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>
mrangel
17 Nov 2024, 10:32I 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.
SummaCivis
25 Nov 2024, 00:57I'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?
mrangel
25 Nov 2024, 14:47Hmm… 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)