diff --git a/src/Story.ts b/src/Story.ts index 7fc0dc7a..8bda8243 100644 --- a/src/Story.ts +++ b/src/Story.ts @@ -1202,7 +1202,7 @@ export class Story extends InkObject{ throw new Error("Can't " + activityStr + '. Story is in the middle of a ContinueAsync(). Make more ContinueAsync() calls or a single Continue() call beforehand.'); } - public ChoosePath(p: Path | null){ + public ChoosePath(p: Path){ this.state.SetChosenPath(p); // Take a note of newly visited containers for read counts etc @@ -1216,6 +1216,7 @@ export class Story extends InkObject{ let choiceToChoose = choices[choiceIdx]; if (choiceToChoose.threadAtGeneration === null) { return throwNullException('choiceToChoose.threadAtGeneration'); } + if (choiceToChoose.targetPath === null) { return throwNullException('choiceToChoose.targetPath'); } this.state.callStack.currentThread = choiceToChoose.threadAtGeneration; @@ -1656,6 +1657,8 @@ export class Story extends InkObject{ let choice = invisibleChoices[0]; + if (choice.targetPath === null) { return throwNullException('choice.targetPath'); } + this.ChoosePath(choice.targetPath); return true; diff --git a/src/StoryState.ts b/src/StoryState.ts index 61b33635..f8eae31c 100644 --- a/src/StoryState.ts +++ b/src/StoryState.ts @@ -12,7 +12,7 @@ import {JsonSerialisation} from './JsonSerialisation'; import {PRNG} from './PRNG'; import {Void} from './Void'; import {Pointer} from './Pointer'; -import { tryGetValueFromMap } from './TryGetResult'; +import {tryGetValueFromMap} from './TryGetResult'; import {Choice} from './Choice'; import {asOrNull, asOrThrows, nullIfUndefined} from './TypeAssertion'; import {JObject} from './JObject'; @@ -20,6 +20,7 @@ import {Debug} from './Debug'; import {Container} from './Container'; import {InkObject} from './Object'; import { throwNullException } from './NullException'; +import { Story } from './Story'; export class StoryState{ @@ -108,7 +109,7 @@ export class StoryState{ public previousRandom: number = 0; public didSafeExit: boolean = false; - public story: any /* Story */; + public story: Story; get currentPathString(){ let pointer = this.currentPointer; @@ -221,7 +222,7 @@ export class StoryState{ this.callStack.currentElement.inExpressionEvaluation = value; } - constructor(story: any /* Story */){ + constructor(story: Story){ this.story = story; this._outputStream = []; @@ -672,7 +673,9 @@ export class StoryState{ rawList.origins.length = 0; for (let n of rawList.originNames) { + if (this.story.listDefinitions === null) return throwNullException('StoryState.story.listDefinitions'); let def = this.story.listDefinitions.TryListGetDefinition(n, null); + if (def.result === null) return throwNullException('StoryState def.result'); if (rawList.origins.indexOf(def.result) < 0) rawList.origins.push(def.result); } } @@ -749,7 +752,7 @@ export class StoryState{ this.callStack.Pop(popType); } - public SetChosenPath(path: Path | null){ + public SetChosenPath(path: Path){ // Changing direction, assume we need to clear current set of choices this._currentChoices.length = 0; diff --git a/src/VariablesState.ts b/src/VariablesState.ts index e2405cb1..f0336bef 100644 --- a/src/VariablesState.ts +++ b/src/VariablesState.ts @@ -86,7 +86,7 @@ export class VariablesState{ } } - constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin){ + constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin | null){ this._globalVariables = new Map(); this._callStack = callStack; this._listDefsOrigin = listDefsOrigin; @@ -173,6 +173,7 @@ export class VariablesState{ if (variableValue.exists) return variableValue.result; + if (this._listDefsOrigin === null) return throwNullException('VariablesState._listDefsOrigin'); let listItemValue = this._listDefsOrigin.FindSingleItemListWithName(name); if (listItemValue) return listItemValue; @@ -306,5 +307,5 @@ export class VariablesState{ private _callStack: CallStack; private _changedVariables: Set | null = new Set(); - private _listDefsOrigin: ListDefinitionsOrigin; + private _listDefsOrigin: ListDefinitionsOrigin | null; }