misc.t file | source file

Adapted for adv3Lite by Eric Eve

adv3Lite Library - miscellaneous definitions

This module contains miscellaneous definitions that don't have a natural grouping with any larger modules, and which aren't complex enough to justify modules of their own.

Summary of Classes

`ArgumentMismatchError BaseObject FinishOption FinishType GameMainDef LCS LibraryError LocType Mood Script SingletonIterator Stance Tip ViaType`

Summary of Global Objects

`adv3LibInit adv3LibPreinit Attached Behind Carrier displayProbe Down emumTabInitializer ExtLocType failVerifyObj finishOptionAmusing finishOptionCredits finishOptionFullScore finishOptionQuit finishOptionRestart finishOptionRestore finishOptionScore finishOptionUndo firstPersonObj ftDeath ftFailure ftGameOver ftVictory Held In IntLocType Into libGlobal libObjectInitializer On oopsTip OutOf Outside PartOf restoreOptionRestoreAnother restoreOptionStartOver Through tipMode Under undoTip unknownDest_ Up varDest_ Worn`

Summary of Global Functions

`cls decimalStr failedRestoreOptions findMatchingTopic findPlayerChar finishGame finishGameMsg getPlayerChar isEmptyStr isListSubset isValidIdentifierName makeMentioned matchCase nilToList objOfKind overrides partitionList processOptions setPlayer str tryInt tryNum valToList`

Global Functions

`cls ( )` | `misc.t[420]`

Clear the main game window. In most cases, you should call this rather than calling the low-level clearScreen() function directly, since this routine takes care of a couple of chores that should usually be done at the same time.

First, we flush the transcript to ensure that no left-over reports that were displayed before we cleared the screen will show up on the new screen. Second, we call the low-level clearScreen() function to actually clear the display window. Finally, we re-display any <ABOUTBOX> tag, to ensure that the about-box will still be around; this is necessary because any existing <ABOUTBOX> tag is lost after the screen is cleared.

`decimalStr (val, decimalPlaces, =, 2)` | `misc.t[2890]`

Function to return a string to display an integer (val) as a decimal number to decimalPlaces decimal places, e.g. decimalStr(123, 2) -> '1.23'. This provides a way of presenting integer values, such as currency, as ones including decimal fractions. For example, we could use an integer property (balance, say) in cents or pence but display it in dollars or pounds via "$<<decimalStr(balance, 2)>>" or "�<<decimalStr(balance)>> (since decimalPlaced deftults to 2).

`failedRestoreOptions ( )` | `misc.t[1086]`

Show failed startup restore options. If a restore operation fails at startup, we won't just proceed with the game, but ask the user what they want to do; we'll offer the options of restoring another game, quitting, or starting the game from the beginning.

`findMatchingTopic (voc, cls, =, Topic)` | `misc.t[1671]`

Find an existing Topic whose vocab is voc. If the cls parameter is supplied it can be used to find a match in some other class, such as Thing or Mentionable.

`findPlayerChar ( )` | `misc.t[2810]`

The findPlayerChar() function is intended for internal library use only, to be called by getPlayerChar() nothing else has yet defined the player character. The findPlayerChar() function first iterates through every Thing defined in the game until it finds one that defines isInitialPlayChar = true. If it finds one it sets gPlayerChar to this value and returns the player char object. Otherwise it creaates a new Player object, moves it into the first room it finds, sets gPlayerChar to the new Player object, issues a warning to the game author that no player char object has been explicitly defined in game code, and returns the new Player object. This enaures that the calling function, getPlsyerChar(), will always be able to return a non-nil object.

`finishGame (extra)` | `misc.t[1075]`

finish the game, offering the given extra options but no message

`finishGameMsg (msg, extra)` | `misc.t[1017]`

Finish the game, showing a message explaining why the game has ended. This can be called when an event occurs that ends the game, such as the player character's death, winning, or any other endpoint in the story.

We'll show a message defined by 'msg', using a standard format. The format depends on the language, but in English, it's usually the message surrounded by asterisks: "*** You have won! ***". 'msg' can be:

- nil, in which case we display nothing
- a string, which we'll display as the message
- a FinishType object, from which we'll get the message

After showing the message (if any), we'll prompt the user with options for how to proceed. We'll always show the QUIT, RESTART, and RESTORE options; other options can be offered by listing one or more FinishOption objects in the 'extra' parameter, which is given as a list of FinishOption objects. The library defines a few non-default finish options, such as finishOptionUndo and finishOptionCredits; in addition, the game can subclass FinishOption to create its own custom options, as desired.

`getPlayerChar ( )` | `misc.t[2789]`

Failsafe Function to get the player character object

`isEmptyStr (str)` | `misc.t[2037]`

A string is empty if it's nil or if when trimmed it's ''

`isListSubset (a, b)` | `misc.t[1644]`

Determine if list a is a subset of list b. a is a subset of b if every element of a is in b.

`isValidIdentifierName (str)` | `misc.t[2860]`

Determine whether str is a valid identifier

`makeMentioned (obj)` | `misc.t[1611]`

Set the mentioned property of obj to true. If obj is supplied as a list, set every object's mentioned property in the list to true. This can be used in room and object descriptions to mark an object as mentioned so it won't be included in the listing.

`matchCase (newTok, oldTok)` | `misc.t[2516]`

Change the case (upper/lower) of a given new string to match the case pattern of the given original string.

We recognize four patterns:

- If the original string has at least one capital letter and no minuscules, we convert the new string to all caps. For example, matchCase('ALPHA-1', 'omicron-7') yields 'OMICRON-7'.

- If the original string has at least one lower-case letter and no capitals, we convert the new string to all lower case. E.g., matchCase('alpha-1', 'OMICRON-7') yields 'omicron-7'.

- If the original string starts with a capital letter, and has at least one lower-case letter and no other capitals, we capitalize the first letter of the new string and lower-case everything else. E.g., matchCase('Alpha-1', 'OMICRON-7') yields 'Omicron-7'.

- Otherwise, we match the case pattern of the input string letter for letter: for each upper-case letter in the original, we capitalize the letter at the corresponding character index in the new string, and likewise with lower-case letters in the original. We leave other characters unchanged. E.g., matchCase('AlPhA-1', 'omicron-7') yields 'OmIcRon-7'.

`nilToList (val)` | `misc.t[1577]`

nilToList - convert a 'nil' value to an empty list. This can be useful for mix-in classes that will be used in different inheritance contexts, since the classes might or might not inherit a base class definition for list-valued methods such as preconditions. This provides a usable default for list-valued methods that return nothing from superclasses.

`objOfKind (obj, cls)` | `misc.t[2785]`

Service function to determine whether obj is ofKind cls when obj might not be an object.

`overrides (obj, base, prop)` | `misc.t[436]`

Determine if the given object overrides the definition of the given property inherited from the given base class. Returns true if the object derives from the given base class, and the object's definition of the property comes from a different place than the base class's definition of the property.

`partitionList (lst, fn)` | `misc.t[1632]`

partitionList - partition a list into a pair of two lists, the first containing items that match the predicate 'fn', the second containing items that don't match 'fn'. 'fn' is a function pointer (usually an anonymous function) that takes a single argument - a list element - and returns true or nil.

The return value is a list with two elements. The first element is a list giving the elements of the original list for which 'fn' returns true, the second element is a list giving the elements for which 'fn' returns nil.

(Contributed by Tommy Nordgren.)

`processOptions (lst)` | `misc.t[1097]`

Process a list of finishing options. We'll loop, showing prompts and reading responses, until we get a response that terminates the loop.

`setPlayer (actor, person, =, 2)` | `misc.t[1687]`

Set the player character to another actor. If the optional second parameter is supplied, it sets the person of the player character; otherwise it defaults to the second person.

`str (val, radix?, isSigned?)` | `misc.t[1559]`

Function to return the string representation of val. This is essentially the same as the intrinsic function toSrring with the added ability of also working with enuma.

`tryInt (val)` | `misc.t[1459]`

Try converting val to an integer. If this results in an integer value, return it, otherwise return nil.

`tryNum (val)` | `misc.t[1512]`

Try converting val to a number (integer or BigNumber); return the number if there is one, otherwise return nil.

`valToList (val)` | `misc.t[1587]`

val to list - convert any value to a list. If it's already a list, simply return it. If it's nil return an empty list. If it's a singleton value, return a one-element list containing it.

Adv3Lite Library Reference Manual
Generated on 08/12/2025 from adv3Lite version 2.2.2