Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
Tutorial explaining how to work with verb reactions in AdventureJS. tutorial, verb reactions, doMoveThatToThis, doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doNestThatToThis, doNestThisToThat, doUnnestThatFromThis, doUnnestThisFromThat, doSubtractSubstanceFromThis, doAddSubstanceToThis, doDestroyThis, doChangeMoisture, doChangeTemperature, doChangeGravity

Start Scripting:Verb Hooks - Reactions

Verb reactions are identical to verb actions, with the exception that they are not tied to specific verbs. You might say that effects are the results of events. For instance, consider "take lantern" or "put spellbook in knapsack" or "throw knife at troll". Each one of these verbs, and many other verbs as well, will result in moving one asset out of a second asset and into a third asset (even considering that the second or third asset may be a room, the same logic applies). The lantern will be moved from the room to the player. The spellbook will be moved from the player to the knapsack. The knife will be moved from the player to the troll (or to the room, if it misses). In cases like these, AdventureJS will check for the existence of four different hooks, and call any code that it finds:

  • direct_object.doRemoveThisFromThat( indirect_object )
  • indirect_object.doRemoveThatFromThis( direct_object )
  • direct_object.doMoveThisToThat( indirect_object )
  • indirect_object.doMoveThatToThis( direct_object )

Authors can use any of these. Or none of them! But you don't have to use all of them (unless you really want to). An author who wants to make something special happen when an asset changes places can tie that code to any of the assets involved. The goal behind this is to offer as much flexibility as possible in letting authors choose how to organize asset code.

Here is a list of verb reactions.

  • doMoveThatToThis - when that asset is moved to this asset
  • doRemoveThisFromThat - when this asset is removed from that asset
  • doRemoveThatFromThis - when that asset is removed from this asset
  • doMoveThisToThat - when this asset is moved to that asset
  • doNestThatToThis - when that character is nested to this asset
  • doNestThisToThat - when this character is nested to that asset
  • doUnnestThatFromThis - when that character is unnested from this asset
  • doUnnestThisFromThat - when this character is unnested from that asset
  • doSubtractSubstanceFromThis - when a substance is subtracted from this asset
  • doAddSubstanceToThis - when a substance is added to this asset
  • doDestroyThis - when this asset is removed from the game
  • doChangeMoisture - when this asset is moistened
  • doChangeTemperature - when this asset is subjected to a change in temperature
  • doChangeGravity - when this asset is subjected to a change in gravity
  • doTieThisToThat - when this rope is tied to that asset
  • doTieThatToThis - when that rope is tied to this asset

Here's an example that hooks into the verb reaction of to the indirect object, using doMoveThatToThis and doRemoveThatFromThis. (Note the order of That and This. Indirect objects will usually use some form of on[Foo]That[Preposition]This)

MyGame.createAsset({
  class: "NPC",
  name: "Elvis",
}),
MyGame.createAsset({
  class: "Room",
  name: "The Building",
  doMoveThatToThis: 
  {
    "Elvis": function() 
    {
      MyGame.print("Elvis has entered The Building! ");
    }
  },
  doRemoveThatFromThis: 
  {
    "Elvis": function() 
    {
      MyGame.print("Elvis has left The Building! ");
    }
  },
}),

Here is a reverse example that hooks into the verb reaction of the direct object using doMoveThisToThat and doRemoveThisFromThat. (Note the order of This and That. Direct objects will usually use some form of on[Foo]This[Preposition]That)

MyGame.createAsset({
  class: "NPC",
  name: "Elvis",
  doMoveThisToThat: 
  {
    "The Building": function() 
    {
      MyGame.print(`Elvis announces his arrival by strumming the opening chords of "Blue Suede Shoes." `);
    }
  },
  doRemoveThisFromThat: 
  {
    "The Building": function() 
    {
      MyGame.print(`Elvis bids farewell by playing the closing chords of "Hound Dog." `);
    }
  },
}),
MyGame.createAsset({
  class: "Room",
  name: "The Building",
}),

Verb reactions are optional methods that authors can use to add custom code. There are numerous effect that may be overridden. In this example, we set the doMoveThatToThis and doRemoveThatFromThis verb reactions in order to print a custom message whenever the player character enters or leaves this particular room.

MyGame.createAsset({
    class: "Room",
    name: "My Room",

    doMoveThatToThis: 
    {
      "My Hero": function() 
      {
        MyGame.print("My Hero has come to My Room! ");
      }
    },
    doRemoveThatFromThis: 
    {
      "My Hero": function() 
      {
        MyGame.print("My Hero has left My Room. ");
      }
    },
    
  },
  


To learn more about verb reactions... TODO