This is an old revision of the document!
Miscellaneous internal utility functions that don't seem to fit anywhere else. You probably won't every need to use any of these, except maybe String.capitalize().
Assuming that it is an array of strings, returns a proper serial-comma-separated description of the list including “and”, or “nothing” if the list is empty.
[ “a two-dollar pistol”, “a Stetson hat”, “a shotgun” ].commaList() returns “a two-dollar pistol, a Stetson hat, and a shotgun”.
[ “a two-dollar pistol”, “a Stetson hat” ].commaList() returns “a two-dollar pistol and a Stetson hat”.
[ “a two-dollar pistol” ].commaList() returns “a two-dollar pistol”.
[].commaList() returns “nothing”.
Assuming an array of PersistentObjects (or subclasses), returns a serial-comma-separated description like .commaList(), but using those objects' .aName fields.
Assuming an array of PersistentObjects (or subclasses), returns a serial-comma-separated description like .commaList(), but using those objects' .theName fields.
If Sugarcube has been put in debug mode (Config.debug = true), logs the given logName and message to the JS console. If Sugarcube is not in debug mode, it does nothing.
A global message queue system to allow the story author to more easily hook into the Inventory and Apparel UIs and display various flavor texts and do other processing while a player is fooling around with Inventory and Apparel.
Not fully implemented. May change as we rejigger the UIs.
Returns the string with the first character capitalized.
: This doesn't work if the first character is a quotation mark or other punctuation, or a number. Does it need to?
todo once the code is refactored.
An array of the id fields of all the things (PersistentObjects and subclasses) contained in this inventory. Duplicates are not allowed. Order does not matter.
This method adds the given item to the inventory. It does not remove it from any other inventories that might already contain it. You probably usually want to use InventoryUI or .move() instead.
This method removes the given item from the inventory.
This method checks to see if the inventory contains the given item.
Check if the inventory is empty.
Returns the fully-instantiated contents of the Inventory.
If a class is passed to filterClass, only items that are of that class (or a subclass thereof) will be included in the returned array.
If a function is passed to filterFunction, that function will be called once for every item in the inventory. If this function returns true, the item will be included in the returned array. If the function returns false, the item will not be included.
When not undefined, the override value sets the value that .toString() returns, ignoring the actual contents (if any) of the inventory.
This is useful for minor characters and objects who do not actually need a fully-featured inventory, as it avoids all the hassle of defining flavor objects to populate the inventory with, that the protagonist will otherwise never be able to interact with. See the Tutorial for details.
Overridden
This is the function used by .get() to sort the inventory contents. It follows the rules of Javascript's (Array).sort(). The default implementation sorts alphabetically, ignoring case.
This function is generally only used by derived classes that need to sort the {@link LibEcho.Inventory|Inventory} differently. Unless you are extending the library, you'll probably never need to use it.
todo once the code is refactored.
Desc