diff --git a/src/scripting/ScriptSubroutine.ts b/src/scripting/ScriptSubroutine.ts index cb4ff991..d5df5472 100644 --- a/src/scripting/ScriptSubroutine.ts +++ b/src/scripting/ScriptSubroutine.ts @@ -3,10 +3,12 @@ import { Script, ScriptHandler } from '@src/Script.js' export class ScriptSubroutine { name: string command: ScriptHandler + invokeType: 'goto' | 'gosub' - constructor(name: string, command: ScriptHandler) { + constructor(name: string, command: ScriptHandler, invokeType: 'goto' | 'gosub' = 'gosub') { this.name = name this.command = command + this.invokeType = invokeType } toString() { @@ -15,10 +17,14 @@ export class ScriptSubroutine { return '' } - return [`>>${this.name} {`, renderedScript, ' return', '}'].join('\n') + return [`>>${this.name} {`, renderedScript, this.invokeType === 'gosub' ? ' return' : ' accept', '}'].join('\n') } invoke() { - return `gosub ${this.name}` + if (this.invokeType === 'gosub') { + return `gosub ${this.name}` + } else { + return `goto ${this.name}` + } } }