misc.tfilesource 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  FinishOption  FinishType  GameMainDef  LCS  LibraryError  Script  SingletonIterator 

Summary of Global Objects  

adv3LibInit  adv3LibPreinit  finishOptionAmusing  finishOptionCredits  finishOptionFullScore  finishOptionQuit  finishOptionRestart  finishOptionRestore  finishOptionScore  finishOptionUndo  ftDeath  ftFailure  ftGameOver  ftVictory  libGlobal  libObjectInitializer  restoreOptionRestoreAnother  restoreOptionStartOver  unknownDest_  varDest_ 

Summary of Global Functions  

cls  failedRestoreOptions  findMatchingTopic  finishGame  finishGameMsg  isEmptyStr  isListSubset  makeMentioned  matchCase  nilToList  overrides  partitionList  processOptions  setPlayer  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.

failedRestoreOptions ( )misc.t[961]
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[1530]
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.

finishGame (extra)misc.t[950]
finish the game, offering the given extra options but no message

finishGameMsg (msg, extra)misc.t[892]
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.

isEmptyStr (str)misc.t[1716]
A string is empty if it's nil or if when trimmed it's ''

isListSubset (a, b)misc.t[1503]
Determine if list a is a subset of list b. a is a subset of b if every element of a is in b.

makeMentioned (obj)misc.t[1470]
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[2195]
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[1436]
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.

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[1491]
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[972]
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[1546]
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.

tryInt (val)misc.t[1328]
Try converting val to an integer. If this results in an integer value, return it, otherwise return nil.

tryNum (val)misc.t[1381]
Try converting val to a number (integer or BigNumber); return the number if there is one, otherwise return nil.

valToList (val)misc.t[1446]
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 28/03/2016 from adv3Lite version 1.5