From 53f08b98b3bc11b7024be1f14ead30c2ffd9d9fb Mon Sep 17 00:00:00 2001 From: Chris Maltby Date: Fri, 28 Jun 2024 17:12:07 +0100 Subject: [PATCH] WIP: Fix issue where actors referenced within scripts were not always being linked correctly --- src/lib/compiler/scriptBuilder.ts | 13 +++++++++++-- src/shared/lib/scripts/scriptDefHelpers.ts | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/compiler/scriptBuilder.ts b/src/lib/compiler/scriptBuilder.ts index 88f1d3aba..0903409a9 100644 --- a/src/lib/compiler/scriptBuilder.ts +++ b/src/lib/compiler/scriptBuilder.ts @@ -2381,6 +2381,9 @@ extern void __mute_mask_${symbol}; if (typeof id === "number") { this.actorIndex = id; this._setConst(addr, this.actorIndex); + } else if (typeof id === "string" && id.startsWith(".")) { + this.actorIndex = -1; + this._set(addr, id); } else if (typeof id === "string") { const newIndex = this.getActorIndex(id); this.actorIndex = newIndex; @@ -3985,7 +3988,10 @@ extern void __mute_mask_${symbol}; // -------------------------------------------------------------------------- // Call Script - callScript = (scriptId: string, input: Dictionary) => { + callScript = ( + scriptId: string, + input: Dictionary + ) => { const { customEvents } = this.options; const customEvent = customEvents.find((ce) => ce.id === scriptId); @@ -4016,7 +4022,8 @@ extern void __mute_mask_${symbol}; if ( typeof variableValue !== "string" && variableValue.type !== "variable" && - variableValue.type !== "number" + variableValue.type !== "number" && + variableValue.type !== "argument" ) { const [rpnOps, fetchOps] = precompileScriptValue( optimiseScriptValue(variableValue) @@ -4057,6 +4064,8 @@ extern void __mute_mask_${symbol}; if (typeof actorValue === "string") { const actorIndex = this.getActorIndex(actorValue); this._stackPushConst(actorIndex, `Actor ${actorArg.id}`); + } else if (actorValue.type === "argument") { + this._stackPush(actorValue.symbol); } } } diff --git a/src/shared/lib/scripts/scriptDefHelpers.ts b/src/shared/lib/scripts/scriptDefHelpers.ts index b35e76791..013b62ba9 100644 --- a/src/shared/lib/scripts/scriptDefHelpers.ts +++ b/src/shared/lib/scripts/scriptDefHelpers.ts @@ -74,6 +74,10 @@ export const isActorField = ( args: ScriptEventArgs, scriptEventDefs: ScriptEventDefs ) => { + // Custom event calls + if (fieldName.startsWith("$actor[")) { + return true; + } const field = getField(cmd, fieldName, scriptEventDefs); return !!field && field.type === "actor" && isFieldVisible(field, args); };