Pre-release
AdventureJS Docs Downloads Devlog
Score: 0 Moves: 0

Extends: AdventureJS.Atom

Defined in: Adventure/Assets/Helpers/Stack.js, line 5

Tutorials: Helpers_Stacks

Description

Stack is a special class that allows entity assets to be split into In this example, we'll set up a custom class Pistachio and then create a dispenser that spawns new instances.

MyGame.createClass({
  class: "Pistachio",
  extend: "Edible",
  singular: "pistachio",
  plural: "pistachios",
  description: function () {
    let msg = "";
    msg = `It's a pistachio. `;
    return msg;
  },
});
MyGame.createAsset({
  class: "Pistachio",
  name: "pistachio",
  place: { in: "small pouch" },
  stack: {

    // If use_stack_name is true, this item will be described
    // using the enumeration property with the class's singular
    // property, eg "three pistachios".
    // If use_stack_name is false, the asset's
    // name will be used, eg "the sack of pistachios".
    // This is intended to help distinguish dispensers.
    // Spawned stacks will default to use_stack_name = true.
    this.use_stack_name = true;

    // enumeration determines how stack numbers are
    // presented. Options are: 
//
  • numeric: 1, 2, 3, 17, 100, etc.
  • //
  • spelled: a, two, three, seventeen, one hundred, etc.
  • //
  • grouped: a, a couple of, several, a few, some, numerous
  • // The enumeration setting carries to spawned stacks. this.enumeration = "spelled"; // numeric, spelled, grouped // Making a stack a dispenser means the whole stack // is a fixed object. For example, // a sack of peanuts, where the sack is an asset, // and the peanuts always reside inside it. // New peanuts can be spawned from the stack, // but the entire stack can't be removed. // Spawned stacks will NOT be dispensers. dispenser: false, // Quantity represents the current count of items // in this stack, which could be 1 or 10 or 1000. // Setting to -1 makes it infinite which is useful // for making bottomless dispensers. quantity: -1, // max_quantity sets the highest quantity that // this stack can hold. Setting to -1 makes it // infinite. If quantity is set to -1, max_quantity // will be ignored. max_quantity: -1, // max_per_take sets the highest quantity that // can be taken from this stack at a time. this.max_per_take = -1; // max_stacks_in_game means the total number of // stacks allowed in the game world, for // example you may want to allow no more // than 50 unique breadcrumbs to be created. // Spawned stacks will always inherit this property // from their originating stack. max_stacks_in_game: 50, // max_quantity_in_game means the total quantity held // by all stacks in the game world. // For instance, you may want to have 5 quivers // of arrows, but no more than 50 arrows between them all. // If any stack of this class has infinite quantity, // this will be infinite. // Spawned stacks will always inherit this property // from their originating stack. max_quantity_in_game: -1, // Stacks spawned by this stack will inherit properties // from this stack, except for dispenser and use_stack_name. // max_quantity and max_per_take can be set uniquely for new stacks. spawn_properties: {}, }, });

    Private Constructor:

    var foo = new Stack(game_name, name)

    Parameters:

    • game_name String
      Name of top level game instance that is scoped to window.
    • name String
      Instance name.
    Inherited Overrides

    Index

    Methods:

    Properties:

    Methods Collapse all  |  Expand all

    getClassInheritance
    getClassInheritance() → {Array}

    Defined in: Adventure/Atom.js, line 200

    Inherited from: AdventureJS.Atom#getClassInheritance

    getClassInheritance is a utility method to get an asset's class inheritance chain. Returns a list of class names from high to low.

    Returns:

    Array
    hasClass
    hasClass(prop) → {Boolean}

    Defined in: Adventure/Atom.js, line 174

    Inherited from: AdventureJS.Atom#hasClass

    Parameters:

    • prop String
      Name of the class to test for.
    A method to test whether the Atom is an instance of a given class.

    Returns:

    Boolean
    set
    set(props) → {Object}

    Defined in: Adventure/Atom.js, line 162

    Overrides from: AdventureJS.Atom#set

    Parameters:

    • props Object
      A generic object containing properties to copy to the Object instance.
    Provides a chainable shortcut method for setting a number of properties on the instance.

    Returns:

    Object Returns the instance the method is called on (useful for chaining calls.)

    Properties  | 

    dispenser
    dispenser :Boolean

    Defined in: Adventure/Assets/Helpers/Stack.js, line 137

    Making a stack a dispenser means the whole stack is a fixed object. For example, a sack of peanuts, where the sack is an asset, and the peanuts always reside inside it. New peanuts can be spawned from the stack, but the entire stack can't be removed. Spawned stacks will NOT be dispensers.
    enumeration
    enumeration :string

    Defined in: Adventure/Assets/Helpers/Stack.js, line 126

    enumeration determines how stack numbers are presented. Options are:
  • numeric: 1, 2, 3, 17, 100, etc.
  • spelled: a, two, three, seventeen, one hundred, etc.
  • grouped: a, a couple of, several, a few, some, numerous
  • The enumeration setting carries to spawned stacks.
    game
    game :Getter

    Defined in: Adventure/Atom.js, line 141

    Inherited from: AdventureJS.Atom#game

    Returns the top level game object. Use this.game.
    id
    id :String

    Defined in: Adventure/Atom.js, line 117

    Inherited from: AdventureJS.Atom#id

    id returns the id of the class instance.
    max_quantity
    max_quantity :int

    Defined in: Adventure/Assets/Helpers/Stack.js, line 160

    Default value: -1

    max_quantity sets the highest quantity that this stack can hold. Setting to -1 makes it infinite. If quantity is set to -1, max_quantity will be ignored.
    max_quantity_in_game
    max_quantity_in_game :int

    Defined in: Adventure/Assets/Helpers/Stack.js, line 191

    max_quantity_in_game means the total quantity held by all stacks in the game world, excluding infinite stacks. For instance, you may want to have 5 quivers of arrows, but no more than 50 arrows between them all. Spawned stacks will inherit this value.
    max_stacks_in_game
    max_stacks_in_game :int

    Defined in: Adventure/Assets/Helpers/Stack.js, line 180

    max_stacks_in_game means the total number of stacks of this class allowed in the game world. For example you may want to allow no more than 50 unique breadcrumbs to be created Spawned stacks will inherit this value.
    max_take
    max_take :int

    Defined in: Adventure/Assets/Helpers/Stack.js, line 170

    Default value: -1

    max_per_take sets the highest quantity that can be taken from this stack at a time. Spawned stacks will inherit this value.
    name
    name :String

    Defined in: Adventure/Atom.js, line 62

    Overrides from: AdventureJS.Atom#name

    Class identifier to be provided in the asset definition. All game objects start as generic objects that get passed to createAsset, which uses an object's class field to specify a class constructor.
    Name
    Name :String

    Defined in: Adventure/Atom.js, line 128

    Inherited from: AdventureJS.Atom#Name

    Name returns the name of the class instance with the first character uppercased.
    quantity
    quantity :int

    Defined in: Adventure/Assets/Helpers/Stack.js, line 149

    Default value: 1

    Quantity represents the current count of items in this stack, which could be 1 or 10 or 1000. Setting to -1 makes it infinite which is useful for making bottomless dispensers. Spawned stacks will start with the quantity taken.
    spawn_properties
    spawn_properties :object

    Defined in: Adventure/Assets/Helpers/Stack.js, line 202

    Stacks spawned by this stack will inherit properties from this stack, except for dispenser and use_stack_name. max_quantity and max_per_take can be set uniquely for new stacks.
    use_stack_name
    use_stack_name :Boolean

    Defined in: Adventure/Assets/Helpers/Stack.js, line 114

    If use_stack_name is true, this item will be described using the enumeration property with the class's singular property, eg "three pistachios". If use_stack_name is false, the asset's name will be used, eg "the sack of pistachios". This is intended to help distinguish dispensers. Spawned stacks will default to use_stack_name = true.