An alternative to compass directions

Virtually all parser games use the compass directions to allow the player to navigate the map. It is a good system, but perhaps it lacks some realism; what if the player has no compass, how would she know which way is north? And if the action takes place in a big city, you might want to give the option for the player to get directly to the bank, without having to map every intersection on the way.

An alternative approach is to give the player a list of destinations. You can do that in Quest (desktop version anyway!) just by giving an exit a new alias. The place will then appear in the list of objects.

What I present here, however, is an alternative approach. This puts all the destinations in their own pane. Furthermore, rather than using a new alias on the exit, it uses the name of the destination room. This means you can paste these into your existing game, and it will just work.

You really need to paste these chunks of code into your game in full code view, and I would very much recommend backing up your game before doing anything in full code view - it has the potential to get you game in a state Quest cannot load.

The first chunk of code needs to be inserted just before this line:

  </game>

You should find that about a dozen lines from the top. The code below needs to go just above it:

    <turnoffcompass />
    <gotoplaceshtml><![CDATA[
            <h3 id="gotoPlacesLabel" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top" style=""><span class="ui-icon ui-icon-triangle-1-s"></span><span class="accordion-header-text">Go to places</span></h3>
            <div id="gotoPlacesAccordion" class="ui-accordion-content-active ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="">
                <div id="gotoPlacesWrapper" class="elementListWrapper">
                    <ol id="lstGotoPlaces" class="elementList ui-selectable" size="3"></ol>
                </div>
                <div id="gotoPlacesButtons" class="verbButtons">
                    <button id="cmdGotoPlaces1" type="button" onclick="ButtonClickGoto();" style="display: none;" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Go to</span></button>
                </div>
            </div>
            <script>
              function SelectGoto(item) {
                $('#lstGotoPlaces').children().removeClass('ui-selected');
                $('#' + item.id).addClass('ui-selected');
                $('#cmdGotoPlaces1').show();
              }
              function ButtonClickGoto() {
                el = $('#lstGotoPlaces').children('.ui-selected')[0];
                ASLEvent("GotoPlace", el.innerHTML);
              }
              function ClearGotoLinks() {
                links = $('[data-elementid="go"]');
                links.contents().unwrap();
              }
            </script>
                                                                ]]></gotoplaceshtml>
    <inituserinterface type="script">
      JS.addScript (game.gotoplaceshtml)
      JS.eval ("$('#gotoPlacesLabel').appendTo('#gamePanesRunning');")
      JS.eval ("$('#gotoPlacesAccordion').appendTo('#gamePanesRunning');")
      if (not game.pov = null) {
        UpdateGotoPlaces
      }
    </inituserinterface>
    <start type="script">
      UpdateGotoPlaces
    </start>

The second chunk needs to go just before this line:

</asl>

You will find that right at the very end. Paste the code before just above that line.

  <function name="FormatExitList" parameters="preList, list, preFinal, postList" type="string"><![CDATA[
    result = ""
    listLength = ListCount(list)
    if (listLength > 0) {
      count = 0
      result = "You can go to "
      foreach (item, list) {
        s = GetDestinationName(item, null)
        if (game.enablehyperlinks) {
          result = result + "{command:go to " + s + ":" + s + "}"
        }
        else {
          result = result + s
        }
        count = count + 1
        if (count = listLength - 1) {
          result = result + " " + preFinal + " "
        }
        else if (count < listLength) {
          result = result + ", "
        }
      }
      result = result + postList
    }
    return (result)
  ]]></function>
  <function name="UpdateGotoPlaces"><![CDATA[
    s = ""
    count = 0
    player.destination_list = NewObjectList()
    foreach (o, ScopeExits()) {
      s = s + "<li class=\"ui-selectee\" onclick=\"SelectGoto(this);\" id=\"goto" + count + "\">" + GetDestinationName(o, game.pov.destination_list) + "</li>"
      count = count + 1
    }
    JS.eval ("$('#lstGotoPlaces').html('" + s + "');")
    JS.eval ("$('#cmdGotoPlaces1').hide();")
  ]]></function>
  <function name="GotoPlace" parameters="name">
    exit = null
    foreach (o, ScopeExits()) {
      if (GetDestinationName(o, null) = name) {
        exit = o
      }
    }
    if (exit = null) {
      error ("Hmm, that failed. Should be going to " + name + " but cannot find an exit that way.")
    }
    MovePlayer (if(HasAttribute(exit, "destination"), exit.destination, exit.to))
  </function>
  <function name="GetDestinationName" parameters="exit, list" type="string">
    // Has to return the display name for this exit, and add the destination to the list, if given
    // Whatever goes in the list must be identifiable for the command
    if (not list = null) {
      list add (list, exit.to)
    }
    return (GetDisplayAlias(exit.to))
  </function>
  <function name="MovePlayer" parameters="loc">
    JS.ClearGotoLinks ()
    game.pov.parent = loc
    UpdateGotoPlaces
  </function>

Hopefully when you go back to the normal GUI view, Quest will load you modified game. You should be able to go in-game, and it just works.

Code

There is some extra book-keeping that needs to be done when the player moves or when an exit is created, destroyed, made visible or made invisible in the current room.

To move the player, use the MovePlayer function, together with the destination. This is done automatically for normal movement, but you will need to do this yourself if there are any points where you have code to do it.

If the exits are changing (this does not apply to locking and unlocking), you need to call UpdateGotoPlaces, which will update the list in the pane on the right.

You may want to call JS.ClearGotoLinks (), which will clear all the existing hyperlinks for going to other rooms. You would then need to print a new list of exits, with links (probably using FormatExitList). You will need to think about what works best for you; it may be reasonable to leave the links. If you do not use hyperlinks, you can ignore this issue altogether (but you still need UpdateGotoPlaces).

Style

If you have stylised your panes, you will want the new pane to match it. The way to do that is to modify the first chunk of code in full code view. In both the top two lines you will see this, towards the end:

style=""

You can insert your own style, in CSS, between the double quotes. Sorry, I could not find a more convenient way!

Redirecting

Occasionally you might want one thing displayed, but the destination to be something else. Perhaps you want the player to see "Outside", but the player ends up in a location called "High Street". The way to handle this is to create a new room called "Outside", and have the exit point to that. But then give the exit a new attribute, "destination", set it to be an object, and point it to the "High Street" room. Now when the player selects outside, she will get taken to the High Street.

You can have any number of exits to the "Outside" room from different rooms, each re-directing the player to a different location.


How does your alternative compare to KV's Nautical Directions Library? (Trying to decide which one to use)


Entirely different really. His is a replacement for compass directions, so "port" replaces "west", and is for use on a ship or spaceship.

My replaces the compass road altogether with a pane that looks like the inventory pane, and lists the destinations by name, and I would suggest using it when the player can go to places without caring where they are, like in a big city, and you want to go to the park, but without worrying about the route.


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

Support

Forums