Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
Tutorial explaining how to take advantage of fields that use getStringOrArrayOrFunction in AdventureJS. tutorial, getSAF, getStringOrArrayOrFunction

Start Scripting:String Array Function

To be completed...

AdventureJS takes advantage of Javascript's weak typing to do something a bit cheeky: for some properties, it will accept string or array or function and smartly figure what to do with each.

Properties that call getStringOrArrayOrFunction

  • verb subscription on_success: asset.[i|d]ov[verb].on_success
  • verb subscription then_destroy: asset.[i|d]ov[verb].then_destroy
  • all descriptions: asset.description and asset.descriptions[any]
  • room events: room.room_events
  • zone events: room.zone.zone_events
  • custom vars: MyGame.world._vars[ property ]
  • constraint message: character.constrained_msg

Get string or array or function. Because Javascript is untyped, we can pass any kind of value in a variable. We take advantage of that here to provide flexibility to authors in properties that print a string back to the player.

  • Strings will be printed as is.
  • Arrays can be set to provide a string from a randomized index, or a sequential index that increments each time it's called.
  • Functions can use their own internal logic to return a string, allowing for dynamic state-based descriptions, such as whether an Asset is open or closed.

Example:

MyGame.createAsset({
  class: "Desk",
  name: "desk",
  descriptions: { look: "An old school wooden desk. ", },
});
MyGame.createAsset({
  class: "Drawer",
  name: "drawer",
  descriptions: {
    look: function(){
      return "The drawer is $( drawer is| open or| closed ). ";
    },
  },
});
MyGame.createAsset({
  class: "Blotter",
  name: "blotter",
  descriptions: {
    look: [
      {randomize: true},
      "The words 'live and let die' are scrawled on the blotter. ",
      "The desk blotter has 'born to bleed' carved into it. ",
      "You see 'zep rulez!' scratched in to the desk blotter. ",
    ],
  },
});

For more information, see How to Use String|Array|Function.

Properties that call getStringOrArrayOrFunction

  • verb subscription on_success: asset.[i|d]ov[verb].on_success
  • verb subscription then_destroy: asset.[i|d]ov[verb].then_destroy
  • all descriptions: asset.description and asset.descriptions[any]
  • room events: room.room_events
  • zone events: room.zone.zone_events
  • custom vars: MyGame.world._vars[ property ]
  • constraint message: character.constrained_msg