Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api:inventory

This is an old revision of the document!


<-- Back

LibTF.Inventory

Inherits From: LibTF.PersistentObject

An Inventory is an object that contains other things. An inventory is used to track items that a Person carries. A different specialized inventory is used to track what Apparel a Person is wearing. A trunk or bookshelf might use an Inventory to track what is held within on on it. In a more traditional sort of location-based Twine IF, each location might even use an inventory to track what items the player can find or has dropped there.

Fields

Inherited from LibTF.PersistentObject: id, parentId, parent, name, aName, nameIsProper, nameIrregularArticle

Methods

Inherited from LibTF.PersistentObject: hasPersistent(), getPersistent(), setPersistent(), resetPersistent()

(Inventory).add( itemOrId )

  • Arguments:
    • itemOrId : the thing to be added to the inventory.
  • Returns: Nothing, although it probably ought to return the thing that was added, or null if it wasn't added…
  • Throws: Error if: itemOrId is invalid or malformed, or if the preAdd() callback does not return a proper Boolean value.

This method adds the given itemOrId to the inventory. It does not remove it from any other inventories that might also contain it. itemOrId may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof).

tfGet("joe").inventory.add( "some_widget" );

(Inventory).remove( itemOrId )

  • Arguments:
    • itemOrId: the thing to be removed from the inventory.
  • Returns: Nothing, although it probably ought to return the thing that was removed, or null if it wasn't removed…
  • Throws: Error if: itemOrId is invalid or malformed, or if the preRemove() callback does not return a proper Boolean value.

This method removes the given itemOrId from the inventory. itemOrId may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof).

tfGet("joe").inventory.remove( "some_widget" );

(Inventory).has( itemOrId )

  • Arguments:
    • itemOrId: the thing to be checked for in the inventory.
  • Returns: (Boolean) True if the inventory contains the specified thing, or False if not.
  • Throws: Error if: itemOrId is invalid or malformed.

This method checks to see if the inventory contains the given itemOrId. itemOrId may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof).

if( tfGet("joe").inventory.has("some_widget") )
	alert( "Joe has a widget!" );

(Inventory).get()

  • Arguments: None.
  • Returns: (Array) An array of fully instantiated PersistentObjects (or subclasses thereof).
  • Throws: Nothing.

Returns an array of fully instantiated PersistentObjects (or subclasses thereof) contained in the inventory.

FIXME: We ought to have a method that just returns ids, too…

alert( "Joe is carrying " + LibTF.Util.commaList(tfGet("joe").inventory.get()) + ".  Kinky." );
// prints "Joe is carrying a ball of string, an octopus, and a European swallow.  Kinky."

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

getListString( examineLink = true )
	{
		let l = [];
		for( let a of this.get() )
		{
			let examinePassage = "Examine."+a.id;
			if( examineLink && Story.has(examinePassage) )
				l.push( "[["+a.aName+"->"+examinePassage+"]]" );
			else
				l.push( a.aName );
		}
		return Util.commaList( l );
	}

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

sort( a, b )
	{
		return a.name.toLowerCase().localeCompare( b.name.toLowerCase() );
	}

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

preAdd( id )
	{
		return true;
	}

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

postAdd( id )
	{
	}

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

preRemove( id )
	{
		return true;
	}

(Inventory).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

postRemove( id )
	{
	}

<-- Back

libtf/documentation/api/inventory.1519585359.txt.gz · Last modified: 2018/02/25 11:02 by lee