StoryState
A story's state - flags, the inventory and how often each node was visited - and the conditions and effects its data can use. Built-in vocabulary is in the Story guide; add your game's own with registerCondition() and registerEffect().
Properties
flags(StoryFlags)inventory(Inventory)items(roAssociativeArray) — item id -> ItemDefinition, from the story's itemsrules(Array.<EventRule>)
Constructor
new StoryState(story?: StoryData): StoryStateParameters
story(StoryData, optional, default: "invalid") — its items and rules are used; may be invalid
Instance Methods
registerCondition(
key: string,
handler: function,
context?: dynamic,
): void
Adds a condition key, e.g. coinsGte. A registered key takes priority over a built-in one.
Parameters
key(string) — the condition's identifying keyhandler(function) — function(condition, state, context) as boolean: true if it passescontext(dynamic, optional, default: "invalid") — passed to the handler (BrightScript functions can't capture variables)
Returns
void
registerEffect(
key: string,
handler: function,
context?: dynamic,
): void
Adds an effect key, e.g. heal.
Parameters
key(string) — the effect's identifying keyhandler(function) — function(effect, state, context) as boolean: true if story state changedcontext(dynamic, optional, default: "invalid") — passed to the handler
Returns
void
findConditionHandler(condition: roAssociativeArray): dynamic
Parameters
condition(roAssociativeArray)
Returns
dynamic— the StoryHandler for a registered key of this condition, or invalid
findEffectHandler(effect: roAssociativeArray): dynamic
Parameters
effect(roAssociativeArray)
Returns
dynamic— the StoryHandler for a registered key of this effect, or invalid
isKnownCondition(condition: roAssociativeArray): boolean
Parameters
condition(roAssociativeArray)
Returns
boolean— true if a key of this condition is built in or registered
isKnownEffect(effect: roAssociativeArray): boolean
Parameters
effect(roAssociativeArray)
Returns
boolean— true if a key of this effect is built in or registered
conditionKeys(condition: roAssociativeArray): Array.<string>
The keys of a condition that name one - built in or registered, not modifiers like eq or gte. A condition should have exactly one: only the first found is evaluated.
Parameters
condition(roAssociativeArray)
Returns
Array.<string>
effectKeys(effect: roAssociativeArray): Array.<string>
The keys of an effect that name one - built in or registered, not modifiers like value or amount. An effect should have exactly one: only the first found runs.
Parameters
effect(roAssociativeArray)
Returns
Array.<string>
evaluate(conditions: Array.<StoryCondition>): boolean
Parameters
conditions(Array.<StoryCondition>) — or invalid (passes)
Returns
boolean— true if every condition passes
applyEffects(effects: Array.<StoryEffect>): StoryResult
Parameters
effects(Array.<StoryEffect>) — or invalid
Returns
runEvent(
eventName: string,
data?: roAssociativeArray,
): StoryResult
Runs every event rule for this event whose match and when pass.
Parameters
eventName(string)data(roAssociativeArray, optional, default: "{}") — the event's data, matched against each rule's match
Returns
settle(): StoryResult
Runs "storyChanged" rules until nothing more changes. Call it after anything changes the story.
Returns
visitCount(key: string): integer
Parameters
key(string) — a node id, a candidate's "#", or a choice's "/"
Returns
integer
recordVisit(key: string): void
Parameters
key(string)
Returns
void
interpolate(text: string): string
Parameters
text(string)
Returns
string— text with each ${flag} filled in
reset(): void
Clears flags, the inventory and visits (for a new game). Registered vocabulary stays.
Returns
void
toSaveData(): StorySaveData
Returns
loadSaveData(data: dynamic): void
Loads toSaveData()'s output. Anything malformed is dropped, so a bad save gives a fresh state.
Parameters
data(dynamic)
Returns
void