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” (note the dot there), 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."
This is the function used by .get() to sort the inventory. It follows the rules of Javascript's (Array).sort().
This function is generally only used by derived classes that need to sort the inventory differently. Unless you are extending the library, you'll probably never need to use it.
This callback method is called before id is added to the inventory. Returning True allows the add to continue, while False will cancel it.
This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors. Unless you are extending the library, you'll probably never need to use this method.
This callback method is called after id has been added to the inventory.
This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors. Unless you are extending the library, you'll probably never need to use this method.
This callback method is called before id is removed from the inventory. Returning True allows the removal to continue, while False will cancel it.
This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors. Unless you are extending the library, you'll probably never need to use this method.
This callback method is called after id has been removed from the inventory.
This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors. Unless you are extending the library, you'll probably never need to use this method.