From dca39adcacfc9cbf1bdc24ff3c00e3c8c9cc2746 Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Tue, 2 Dec 2025 19:00:58 -0800 Subject: [PATCH] explain why onMissionLoadDone is necessary --- src/torqueScript/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/torqueScript/index.ts b/src/torqueScript/index.ts index d29c9f91..a63e8ad4 100644 --- a/src/torqueScript/index.ts +++ b/src/torqueScript/index.ts @@ -92,7 +92,6 @@ export function runServer(options: RunServerOptions): RunServerResult { // Load all required scripts const serverScript = await runtime.loadFromPath("scripts/server.cs"); signal?.throwIfAborted(); - // These are dynamic exec() calls in server.cs since their paths are // computed based on the game type and mission. So, we need to load them // ahead of time so they're available to execute. @@ -104,7 +103,13 @@ export function runServer(options: RunServerOptions): RunServerResult { // Execute server.cs - it will exec() the game type and mission scripts serverScript.execute(); - // Set up mission ready hook + // Set up mission ready hook. It's unfortunate that we have to do it this + // way, but there's no event system in TorqueScript. The problem is that + // `CreateServer` will defer some actions using `schedule()`, so the + // objects are created some arbitrary amount of time afterward, and we + // don't actually know when they're ready. But, we can spy on the + // `missionLoadDone` method using the runtime's `onMethodCalled` feature, + // which we added specifically to solve this problem. if (onMissionLoadDone) { runtime.$.onMethodCalled( gameTypeName,