State class | thing.t[957]

A State represents a changeable condition of a Mentionable that can be used as part of the object's name in command input. For example, a state could be used to represent whether a match is lit or unlit: the words 'lit' and 'unlit' could then be used to describe the object, according to its current condition.

The actual current condition of a given object is given by a property of the Mentionable, which we define as part of the State object. So testing whether an object is lit or unlit is just a matter of checking the corresponding property of the object.

The parser considers an object to have the state, for parsing purposes, if the object defines any value for the state property.

Most of the State object's definition is its vocabulary, which is obviously language-specific. We therefore leave it to the language modules to define the individual State instances. Games can also add new states as needed, of course.

`class State : LState`

Superclass Tree (in declaration order)

`State`
`LState`
`object`

Subclass Tree

(none)

Global Objects

`DirState LitUnlit OpenClosed`

Summary of Properties

`adjectives all stateProp vocabTab vocabWords`

Inherited from `LState` :
`additionalInfo`

Summary of Methods

`appliesTo classInit construct getVocab matchName`

Inherited from `LState` :
`addToName getAdditionalInfo initWord`

Properties

`adjectives` | `thing.t[1030]`

State/adjective initializer list.

States are generally represented in names by adjectives added to the object name, both in displaying output and in parsing input. For example, a Lit/Unlit state would add 'lit' in the lit state and 'unlit' in the unlit state. So we provide an easy way of initializing a state object: just list the states and their corresponding adjectives.

Make one entry in this list for each possible state; the entry is a list, [stateval, [adjectives]], where 'stateval' is the state variable value, and [adjectives] is a list of strings giving the corresponding adjectives. The first adjective in the list is the display adjective - this is the one that addToName() will use to generate an object name for display. The rest are used to parse input; they'll all be matched to the state.

`all` | `thing.t[1046]`

class property: master list of all State objects

`stateProp` | `thing.t[966]`

The Mentionable property that indicates the current condition of an object that has this State. The range of values that this property takes on in the Mentionable is up to the State to define. For some states, this will be a simple boolean: Lit/Unlit, Open/Closed, On/Off, etc. For others, this might be an integer range or a set of string values.

`vocabTab` | `thing.t[1010]`

state vocabulary lookup table (built automatically during preinit)

`vocabWords` | `thing.t[1043]`

*Full* vocabulary initializer list. If the 'adjectives' list isn't sufficiently flexible for your needs, you can use this initializer list instead. This consists of a list of sublist entries, [stateval, word, flags]. 'stateval' is a state value, 'word' is a string giving a vocabulary word to match, and 'flags' is a combination of MatchXxx flags for the word.

[[nil, 'unlit', MatchAdj],
[true, 'lit', MatchAdj]]

Methods

`appliesTo (obj)` | `thing.t[973]`

Does this state apply to the given object? By default, we consider any object that defines the state property to exhibit the state.

`classInit ( )` | `thing.t[1091]`

class initialization

`construct ( )` | `thing.t[1049]`

construction

`getVocab (state)` | `thing.t[1003]`

Get the vocabulary words that apply to the given state. For example, a Lit/Unlit object might return 'lit' if state is true and 'unlit' if state is nil.

`matchName (tok, state, cmp)` | `thing.t[987]`

Match a token from the object name for the given state value. Mentionable.matchName() calls this to see if a token applies because of the object's current conditdion. 'tok' is the token string; 'state' is the object's value for the state property; and 'cmp' is the string comparator to use for the string comparisons. Returns a combination of MatchXxx flags, or zero if the token doesn't match the current condition.

For example, a Lit/Unlit state would return MatchAdj for 'lit' if 'state' is true, 0 otherwise.

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