Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
Tutorial explaining how to use the AdventureJS goalcard methods. tutorial, goalcard methods

Goals, Hints, and Scores:Goalcards

Goalcards are a system for creating and displaying goals to the player. Goals aren't managed automatically - it's up to authors to define them and determine when they're activated or completed. The first thing an author needs to do is create a set of goals via shorthand or longhand methods. A player might see something like the following in response to typing goals:

example output

> goals
  • You must find shelter.
  • You must find water.
  • You must find food.
  • You must find warmth.

Methods

  • MyGame.goalcard.set({}) {Object} an object containing goal definitions MyGame.goalcard Use this to add goal data to the goalcard.
    Expand for example
    MyGame.gamecard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          text: `You must find shelter.`,
          complete: true,
          complete_text: `You found shelter.`,
        },
      },
    });
  • MyGame.goalcard.activateGoal("goal name") {String} name - the name of a goal {Boolean} recurse - whether to recursively apply to nested goals. Default is true. Boolean - true on success, false on failure Use this to activate a goal, and optionally any nested goals. This can be called from any code block.
    Expand for example
    MyGame.gamecard.activateGoal("find shelter");
  • MyGame.goalcard.deactivateGoal("goal name") {String} name - the name of a goal {Boolean} recurse - whether to recursively apply to nested goals. Default is true. Boolean - true on success, false on failure Use to deactivate a goal, and optionally any nested goals. Use it like this.
    Expand for example
    MyGame.gamecard.deactivateGoal("find shelter");
  • MyGame.goalcard.completeGoal("goal name") {String} name - the name of a goal {Boolean} recurse - whether to recursively apply to nested goals. Default is true. Boolean - true on success, false on failure Use this to complete a goal, and optionally any nested goals.
    Expand for example
    MyGame.gamecard.completeGoal("find shelter");

Properties

Goal Properties

Goals will never be automatically activated / deactivated / completed by the goal system; it's up to authors to control goal states through goalcard methods.

  • MyGame.goalcard["my goal"].name {String} goal.name is set automatically from the object key. It isn't presented to players, but is used as a key so that authors may refer to the goal by name, in code, through methods such as game.goalcard.activateGoal("my goal").
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          active: true,
          text: `You must find shelter.`,
          complete: false,
          complete_text: `You found shelter.`,
        },
      },
    });
        
  • MyGame.goalcard["my goal"].text {String} goal.text is the text to be presented to players in a list of goals.
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          active: true,
          text: `You must find shelter.`,
          complete: false,
          complete_text: `You found shelter.`,
        },
      },
    });
        
  • MyGame.goalcard["my goal"].complete {Boolean} goal.complete is a boolean used to determine whether the goal has been completed. complete is set false by default so you don't actually need to provide it unless you're setting it true at game's start. Though it's unlikely that you'd want to show a goal as completed at the game's start, it's not impossible; for instance if you wanted to start a game in media res, with some goals completed already. Authors can mark goals complete from any code block by calling game.goalcard.completeGoal("my goal").
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          active: true,
          text: `You must find shelter.`,
          complete: false,
          complete_text: `You found shelter.`,
        },
      },
    });
    
    MyGame.gamecard.completeGoal("find shelter");
        
  • MyGame.goalcard["my goal"].complete_text {String} goal.complete_text is the text to be presented in a list of goals if the goal has been completed and game.settings.show_completed_goals is set to true. This is an optional field. If game.settings.show_completed_goals is true and a completed goal's complete_text property is unset, the text property will be used. Completed goals have a special CSS class applied to them that will display them in a different color, so even if no complete_text property is set, the goal will stand apart from incomplete goals.
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          active: true,
          text: `You must find shelter.`,
          complete: false,
          complete_text: `You found shelter.`,
        },
      },
    });
        
  • MyGame.goalcard["my goal"].active {Boolean} goal.active is a boolean used to determine whether the goal should be included in a list of goals. Goals are active by default. Inactive goals are not shown to players. Authors can change this during the game through the use of game.goalcard.activateGoal("my goal") and game.goalcard.deactivateGoal("my goal").
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "find shelter": {
          active: true,
          text: `You must find shelter.`,
          complete: false,
          complete_text: `You found shelter.`,
          active: false,
        },
      },
    });
    
    MyGame.gamecard.activateGoal("find shelter");
    
    MyGame.gamecard.deactivateGoal("find shelter");
    
  • MyGame.goalcard["my goal"].goals {Object} goal.goals is a container for nested goals. Adding nested goals to any goal turns that goal into a goal group.
    Expand for example
    MyGame.goalcard.set({
      introduction: `These are my goals. `,
      goals: {
        "Life at School": {
          active: true,
          text: `The education of a young artist.`,
            goals: {
            "Learn to act": {
              active: true,
              text: `Take an acting class.`,
              complete_text: `You trod the boards.`,
            },
          },
        },
      },
    });