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."
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 ); }
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 ) { }