This is an old revision of the document!
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.
Inherited from LibTF.PersistentObject: id, parentId, parent, name, aName, nameIsProper, nameIrregularArticle
Inherited from LibTF.PersistentObject: hasPersistent(), getPersistent(), setPersistent(), resetPersistent()
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" );
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" );
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!" );
Returns an array of fully instantiated PersistentObjects (or subclasses thereof) contained in the inventory.
: 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."
Returns a natural language string describing the contents of the inventory.
If examineLink is True, the returned string will contain links to any “examine passages” available for objects in the inventory. For example, if there is an object with the id “octopus”, and you create a passage titled “Examine.octopus”, then a link to that passage will be included in the returned string. This is useful for examining or manipulating objects in inventory.
// Assuming that there is a passaged titled "Examine.octopus", but none for the ball of string or the swallow... alert( "Joe is carrying " + tfGet("joe").inventory.getListString() + ". Kinky." ); // prints "Joe is carrying a ball of string, [[an octopus->Examine.octupus]], and a European swallow. Kinky."
Description.
sort( a, b ) { return a.name.toLowerCase().localeCompare( b.name.toLowerCase() ); }
Description.
preAdd( id ) { return true; }
Description.
postAdd( id ) { }
Description.
preRemove( id ) { return true; }
Description.
postRemove( id ) { }