Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api:inventory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
libtf:documentation:api:inventory [2018/02/25 11:13] – [(Inventory).getListString( examineLink = true )] leelibtf:documentation:api:inventory [2018/09/24 18:07] (current) – removed lee
Line 1: Line 1:
-[[libtf:documentation:api:start|<-- Back]] 
- 
- 
-====== LibTF.Inventory====== 
- 
-**Inherits From:** [[libtf:documentation:api:persistentobject|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:documentation:api:persistentobject|LibTF.PersistentObject]]:** id, parentId, parent, name, aName, nameIsProper, nameIrregularArticle 
- 
- 
-===== Methods ===== 
- 
-**Inherited from [[libtf:documentation:api:persistentobject|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). 
- 
-<code javascript> 
-tfGet("joe").inventory.add( "some_widget" ); 
-</code> 
- 
- 
-==== (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). 
- 
-<code javascript> 
-tfGet("joe").inventory.remove( "some_widget" ); 
-</code> 
- 
- 
-==== (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). 
- 
-<code javascript> 
-if( tfGet("joe").inventory.has("some_widget") ) 
- alert( "Joe has a widget!" ); 
-</code> 
- 
- 
-==== (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... 
- 
-<code javascript> 
-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." 
-</code> 
- 
- 
-==== (Inventory).getListString( examineLink = true ) ==== 
- 
-  * **Arguments:** 
-    * **//examineLink://** set to True to include links to object passages in the returned value. 
-  * **Returns:** (String)  A string listing the contents of the inventory, or "Nothing" if the inventory is empty. 
-  * **Throws:** Nothing. 
- 
-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. 
- 
-<code javascript> 
-// 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." 
-</code> 
- 
- 
-==== (Inventory).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-sort( a, b ) 
- { 
- return a.name.toLowerCase().localeCompare( b.name.toLowerCase() ); 
- } 
-</code> 
- 
- 
-==== (Inventory).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-preAdd( id ) 
- { 
- return true; 
- } 
-</code> 
- 
- 
-==== (Inventory).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-postAdd( id ) 
- { 
- } 
-</code> 
- 
- 
-==== (Inventory).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-preRemove( id ) 
- { 
- return true; 
- } 
-</code> 
- 
- 
-==== (Inventory).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-postRemove( id ) 
- { 
- } 
-</code> 
- 
- 
-[[libtf:documentation:api:start|<-- Back]] 
  
libtf/documentation/api/inventory.1519586013.txt.gz · Last modified: 2018/02/25 11:13 by lee