Random exits for random rooms

A section of my game has a series of rooms where the locations of the rooms will be different each time you played the game.
In the example below, I want the 'Stone Path' and the 'Woodland Glen' to be fixed points, but the rooms under the heading 'Section_Forest', to be randomised, with maybe more than one exit to the rooms, so a random maze, between the two rooms.
I've put the 'north' exit in from the 'woodland glen', so i can make sure its the same path, within the game, but different each time the game is played.
I've had a go at starting the process off by 'going east from the stone path' takes you to a random room from the 'Section_Forest' list, but its all the connections in between that I need the help with.

<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Test - Random Rooms">
    <gameid>4bb0f984-8b49-4e7a-ac3c-5bdd45279561</gameid>
    <version>1.0</version>
    <firstpublished>2022</firstpublished>
    <start type="script">
      game.ForestList = NewObjectList()
      foreach (o, GetDirectChildren(Section_Forest)) {
        // msg (o.name)
        list add (game.ForestList, o)
      }
    </start>
    <attr name="autodescription_youarein_useprefix" type="boolean">false</attr>
    <attr name="autodescription_description" type="int">2</attr>
    <attr name="autodescription_youcansee" type="int">3</attr>
    <attr name="autodescription_youcango" type="int">4</attr>
  </game>
  <object name="stone_path">
    <inherit name="editor_room" />
    <isroom />
    <usedefaultprefix />
    <descprefix>You are on</descprefix>
    <alias>stone path</alias>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="east">
      <inherit name="eastdirection" />
      <runscript />
      <script type="script">
        firsttime {
          stone_path.PickForest = PickOneObject (game.ForestList)
          // msg (stone_path.PickForest)
          create exit ("west", stone_path.PickForest, stone_path)
          MoveObject (player, stone_path.PickForest)
        }
        otherwise {
          MoveObject (player, stone_path.PickForest)
        }
      </script>
    </exit>
    <exit alias="south" to="woodland_glen">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="Section_Forest">
    <inherit name="editor_room" />
    <object name="clearing">
      <inherit name="editor_room" />
      <alias>clearing</alias>
    </object>
    <object name="pine_grove">
      <inherit name="editor_room" />
      <alias>pine grove</alias>
    </object>
    <object name="birches">
      <inherit name="editor_room" />
      <alias>birches</alias>
    </object>
    <object name="twilight">
      <inherit name="editor_room" />
      <alias>twilight</alias>
    </object>
    <object name="eerie_copse">
      <inherit name="editor_room" />
      <alias>eerie copse</alias>
    </object>
    <object name="willow">
      <inherit name="editor_room" />
      <alias>willow</alias>
    </object>
  </object>
  <object name="woodland_glen">
    <inherit name="editor_room" />
    <alias>woodland glen</alias>
    <exit alias="north" to="stone_path">
      <inherit name="northdirection" />
    </exit>
  </object>
</asl>

I'm not using the built-in map, so not really bothered about overlapping rooms, etc

Any help is gratefully received

Still struggling with trying to create random exits to random rooms, if anyone can help.


Still having problems with this, but I have come up with a solution of sorts, well two actually, both are in the following game.
The first one is the Section_Forest, which is quite linear, as the random location is decided by the players move and not perfect.
The second solution is the Section_Maze, which randomises the rooms at the start, but I'm having problems with the random element picking the same location for the exit leading to the same room.
I had a go at trying to solve the problem by creating the function 'GetRandomLocation(MazeList)',but that produced an error message.
Anyway, here Is what I've done so far, and as always, any help is much appreciated.

<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Test - Random Rooms">
    <gameid>4bb0f984-8b49-4e7a-ac3c-5bdd45279561</gameid>
    <version>1.0</version>
    <firstpublished>2022</firstpublished>
    <attr name="autodescription_youarein_useprefix" type="boolean">false</attr>
    <attr name="autodescription_description" type="int">2</attr>
    <attr name="autodescription_youcansee" type="int">3</attr>
    <attr name="autodescription_youcango" type="int">4</attr>
    <start type="script">
      game.DirectionMasterList = NewStringList()
      foreach (o, Split("north;south;east;west")) {
        list add (game.DirectionMasterList, o)
      }
      // msg ("Direction Master List" + game.DirectionMasterList)
    </start>
    <feature_annotations />
  </game>
  <object name="stone_path">
    <inherit name="editor_room" />
    <isroom />
    <usedefaultprefix />
    <descprefix>You are on</descprefix>
    <alias>stone path</alias>
    <beforeenter type="script">
    </beforeenter>
    <onexit type="script">
    </onexit>
    <enter type="script">
    </enter>
    <WhatIf type="int">4</WhatIf>
    <beforefirstenter type="script">
      GetRandomRoom (this, game.ForestList, woodland_glen)
    </beforefirstenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="south" to="woodland_glen">
      <inherit name="southdirection" />
      <runscript type="boolean">false</runscript>
      <message type="string"></message>
      <script type="script">
      </script>
    </exit>
    <exit alias="east" to="Maze1">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="Section_Forest">
    <inherit name="editor_object" />
    <feature_startscript />
    <attr name="_initialise_" type="script">
      // msg ("Initialise (game.ForestList)")
      game.ForestList = NewObjectList()
      foreach (o, GetDirectChildren(Section_Forest)) {
        // msg (o.name)
        list add (game.ForestList, o)
      }
    </attr>
    <object name="clearing">
      <inherit name="editor_room" />
      <alias>clearing</alias>
      <beforeenter type="script">
      </beforeenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
      <firstenter type="script">
      </firstenter>
    </object>
    <object name="pine_grove">
      <inherit name="editor_room" />
      <alias>pine grove</alias>
      <beforeenter type="script">
      </beforeenter>
      <firstenter type="script">
      </firstenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
    </object>
    <object name="birches">
      <inherit name="editor_room" />
      <alias>birches</alias>
      <beforeenter type="script">
      </beforeenter>
      <firstenter type="script">
      </firstenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
    </object>
    <object name="twilight">
      <inherit name="editor_room" />
      <alias>twilight</alias>
      <beforeenter type="script">
      </beforeenter>
      <firstenter type="script">
      </firstenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
    </object>
    <object name="eerie_copse">
      <inherit name="editor_room" />
      <alias>eerie copse</alias>
      <beforeenter type="script">
      </beforeenter>
      <firstenter type="script">
      </firstenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
    </object>
    <object name="willow">
      <inherit name="editor_room" />
      <alias>willow</alias>
      <beforeenter type="script">
      </beforeenter>
      <firstenter type="script">
      </firstenter>
      <beforefirstenter type="script">
        GetRandomRoom (this, game.ForestList, woodland_glen)
      </beforefirstenter>
    </object>
  </object>
  <object name="woodland_glen">
    <inherit name="editor_room" />
    <alias>woodland glen</alias>
    <exit alias="north" to="stone_path">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="Section_Maze">
    <feature_startscript />
    <attr name="_initialise_" type="script">
      GetRandomMaze (stone_path)
    </attr>
    <attr name="implementation_notes"><![CDATA[Problems to solve<br/><br/>RandomMazeLocation - PickOneObject(MazeList)<br/>How to prevent it being the same location as you are currently in<br/><br/>If the above line is changed to:<br/>RandomMazeLocation - GetRandomLocation(MazeList)<br/>Error]]></attr>
    <object name="Maze1">
      <inherit name="editor_room" />
    </object>
    <object name="Maze2">
      <inherit name="editor_room" />
    </object>
    <object name="Maze3">
      <inherit name="editor_room" />
    </object>
    <object name="Maze4">
      <inherit name="editor_room" />
    </object>
    <object name="Maze5">
      <inherit name="editor_room" />
    </object>
    <object name="Maze6">
      <inherit name="editor_room" />
    </object>
    <object name="Maze7">
      <inherit name="editor_room" />
    </object>
    <object name="Maze8">
      <inherit name="editor_room" />
    </object>
  </object>
  <function name="GetRandomRoom" parameters="room, SectionList, endroom"><![CDATA[
    if (GetBoolean(endroom, "created")) {
      // msg ("Exits for " + endroom.name + " created - no further rooms in list")
    }
    else {
      room.directionlist = game.DirectionMasterList
      // msg ("Exits For this room: " + ScopeExitsForRoom(room))
      foreach (o, ScopeExitsForRoom(room)) {
        // msg (o.alias)
        list remove (room.directionlist, o.alias)
      }
      // msg ("Available exits for " + room.name + ": " + room.directionlist)
      // msg ("List Count (" + SectionList + "): " + ListCount(SectionList))
      // msg ("room.directionlist" + ListCount(room.directionlist))
      if (ListCount(SectionList) > 0) {
        // msg ("List Count: Greater than 0")
        room.RandomLocation = PickOneObject (SectionList)
        list remove (SectionList, room.RandomLocation)
      }
      else {
        if (not GetBoolean(endroom, "created")) {
          SetObjectFlagOn (endroom, "created")
          // msg ("List Count: Equals 0")
          room.RandomLocation = endroom
          foreach (o, ScopeExitsForRoom(endroom)) {
            direction = o.alias
            switch (direction) {
              case ("north") {
                reverse = "south"
              }
              case ("south") {
                reverse = "north"
              }
              case ("west") {
                reverse = "east"
              }
              case ("east") {
                reverse = "west"
              }
            }
            list remove (room.directionlist, reverse)
            // msg ("Exits for " + endroom + ": " + o.alias)
            // msg ("Exits for " + endroom + ": " + direction)
            // msg ("Exits for " + endroom + " removed: " + reverse)
          }
        }
      }
      direction = PickOneString(room.directionlist)
      switch (direction) {
        case ("north") {
          reverse = "south"
        }
        case ("south") {
          reverse = "north"
        }
        case ("west") {
          reverse = "east"
        }
        case ("east") {
          reverse = "west"
        }
      }
      // msg ("Room Picked: " + room.RandomLocation.name)
      // msg ("New " + SectionList)
      // msg ("Exit from " + room.name + " to " + room.RandomLocation.name + ": " + direction)
      // msg ("Exit from " + room.RandomLocation.name + " to " + room.name + ": " + reverse)
      create exit (direction, room, room.RandomLocation, direction+"direction")
      create exit (reverse, room.RandomLocation, room, reverse+"direction")
      // msg ("Random Chance script for additional exits")
      if (RandomChance(50)) {
        // msg ("Random Chance Active!!!")
        if ((ListCount(SectionList) > 1) and (ListCount(room.directionlist) > 1)) {
          // msg ("Random Chance - Pass")
          GetRandomRoom (room, SectionList, woodland_glen)
        }
        else {
          // msg ("Random Chance - Fail")
        }
      }
    }
  ]]></function>
  <function name="GetRandomMaze" parameters="endroom">
    MazeList = NewObjectList()
    foreach (o, GetDirectChildren(Section_Maze)) {
      // msg (o.name)
      list add (MazeList, o)
    }
    dir = Split("north;south;east;west")
    RandomDirection = PickOneString(dir)
    foreach (room, MazeList) {
      // msg (room.name)
      foreach (direction, dir) {
        RandomMazeLocation = PickOneObject(MazeList)
        if ((room = Maze8) and (direction = RandomDirection)) {
          RandomMazeLocation = endroom
        }
        // msg (direction + " - " + RandomMazeLocation.name)
        create exit (direction, room, RandomMazeLocation, direction+"direction")
      }
    }
  </function>
  <function name="GetRandomLocation" parameters="room, list" type="object">
    location = PickOneObject(list)
    if (room = location) {
      GetRandomLocation (room, list)
    }
    else {
      return (location)
    }
  </function>
</asl>

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

Support

Forums