Stateclass | thing.t[805]

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[878]`

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[894]`

class property: master list of all State objects

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

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[858]`

state vocabulary lookup table (built automatically during preinit)

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

*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[821]`

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[939]`

class initialization

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

construction

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

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[835]`

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 12/12/2022 from adv3Lite version 1.6