Hitchhiker's Guide Gag in Quest

K.V.

Hello.

First, I'd like to thank mrangel for helping me out when I couldn't figure out which parameter to check in this code!


In the Hitchhiker's Guide to the Galaxy, a bad command is thrown back in the player's face towards the end of the game.

To do this in Quest, we can use an attribute to save an unrecognized command. (I'll just set it up to keep track of the last unrecognized command, which should still be fresh on the player's mind.)

Add the attribute unresolvedcommandhandler to your game object. Set it as a script.

To do that, add this to your start script:

game.unresolvedcommandhandler => {
  game.pov.lasterror = command
  msg (Template("UnrecognisedCommand"))
}

UPDATE

That will catch unrecognized commands, but not unrecognized objects. Thanks to mrangel, we can catch those commands, too. Add this to the start script, too:

game.changedunresolvedcommandkey => {
  if (not game.unresolvedcommandkey = null) {
    game.pov.lasterror = game.pov.currentcommand
  }
}
game.pov.changedunresolvedcommandkey => {
  if (not game.unresolvedcommandkey = null) {
    game.pov.lasterror = game.pov.currentcommand
  }
}

From there, you can do whatever you wish with game.pov.lasterror.

In this example, I will create a room called the Hall of Humility.

image


I will create a turn script named "humiliation_turnscript" in this room, making sure to enable it. In a real game*, if there is no last error (which is highly unlikely), the turn script will do nothing.

* This game only has 2 rooms. You'll have to enter a bad command on purposes.

This is my script in code view:

if (HasAttribute(game.pov, "lasterror") and not game.pov.lasterror = "") {
  msg ("<br/>The speaker begins to hum.  You hear some idiot saying, \""+game.pov.lasterror+", "+game.pov.lasterror+", "+game.pov.lasterror+"...\"")
}

Here it is in the GUI:

image



The Example Game's Code:

<!--Saved by Quest 5.8.6716.5372-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Hitchhiker's Gag">
    <gameid>90eed04e-7ed5-4e7d-ab7f-395f7286d9cc</gameid>
    <version>2.0</version>
    <firstpublished>2018</firstpublished>
    <attr name="autodescription_youarein_useprefix" type="boolean">false</attr>
    <attr name="autodescription_youcansee" type="int">3</attr>
    <attr name="autodescription_youcango" type="int">4</attr>
    <attr name="autodescription_description" type="int">2</attr>
    <unresolvedcommandhandler type="script">
      game.pov.lasterror = command
      msg (Template("UnrecognisedCommand"))
    </unresolvedcommandhandler>
    <start type="script"><![CDATA[
      game.changedunresolvedcommandkey => {
        if (not game.unresolvedcommandkey = null) {
          game.pov.lasterror = game.pov.currentcommand
        }
      }
      game.pov.changedunresolvedcommandkey => {
        if (not game.unresolvedcommandkey = null) {
          game.pov.lasterror = game.pov.currentcommand
        }
      }
    ]]></start>
  </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="Hall of Humility">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="Hall of Humility">
    <inherit name="editor_room" />
    <description><![CDATA[A long, narrow hallway. There is a louvered, metal grille in the ceiling, which keeps adventurers like you from destroying the speaker behind it.<br/>]]></description>
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <objectslistprefix>You can see</objectslistprefix>
    <enter type="script">
    </enter>
    <exit alias="south" to="room">
      <inherit name="southdirection" />
    </exit>
    <object name="louvered metal grille">
      <inherit name="editor_object" />
      <look><![CDATA[A 2' by 2' grille, made of steel and painted white.  It looks a little worn for wear, as if someone had tried to run a train through it a few times, but still appears as sturdy as can be.<br/>]]></look>
      <takemsg>You can't reach it.</takemsg>
      <not_all />
      <scenery />
    </object>
    <object name="speaker">
      <inherit name="editor_object" />
      <takemsg>{notfirst:You can't reach it.}{once:Even if you could reach it, you couldn't get past the grille.}</takemsg>
      <not_all />
      <scenery />
      <look>A large speaker, strategically placed behind a metal grille.</look>
    </object>
    <turnscript name="humiliation_turnscript">
      <enabled />
      <script><![CDATA[
        if (HasAttribute(game.pov, "lasterror") and not game.pov.lasterror = "") {
          msg ("<br/>The speaker begins to hum.  You hear some idiot saying, \""+game.pov.lasterror+", "+game.pov.lasterror+", "+game.pov.lasterror+"...\"")
        }
      ]]></script>
    </turnscript>
  </object>
</asl>

That is pretty damn neat. I mean, that's like cooler than a digital watch! You guys are real hoopy froods for sure!


(NOTE: Unrecognized objects don't count!)

Sounds like a challenge:

<turnscript name="error_trap">
  <enabled />
  <script>
    if (HasString (game.pov, "unresolvedcommandkey") or HasString (game, "unresolvedcommandkey")) {
      game.pov.lasterror = game.pov.currentcommand
    }
  </script>
</turnscript>

(unresolvedcommandkey is a variable name ("object1", "object", etc) which the parser failed to match to any object. It is cleared at the start of parsing a command, so in the case of commands separated with dots, this will only catch errors in the last command on a line. It's currently game.unresolvedcommandkey, but there's a comment saying "TODO" move it to game.pov. so I figured it's easier to check for both)


K.V.

...and mrangel shoots the three!

HE'S ON FIRE!!!


The turn script didn't work for some reason, but I got it working with a changed script.

The example has been revised.

Thanks, mrangel!


K.V.

Thanks, Jennifer! Ya' zarkin' frood!


Thanks :)

You could also do it by overriding the (counter-intuitively named) function UnresolvedCommand; but that could cause a game to break if that command's behaviour changes in a future version of Quest. More stable to check the attributes that function sets.


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

Support

Forums