CulturedCait Posted 19 hours ago Report Share Posted 19 hours ago Hi guys! I'm working on a new script and I was wondering if there is a way to execute Engine.SetSimRate / Engine.GetSimRate from JS trigger script? It works if executed directly from the console, but using these functions inside JS produces following error: ERROR: Error in timer on entity 1, IID103, function DoAction: TypeError: Engine.SetSimRate is not a function This is my test trigger: Trigger.prototype.TestDelay = () => { Engine.SetSimRate(20); } const trg = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); trg.DoAfterDelay(5000,"TestDelay", {enabled: true}); I'm on release-a27.1 6a576. Do you have an idea how to change simulation speed from within javascript? Is it even possible using trigger mechanics? Thank you. Quote Link to comment Share on other sites More sharing options...
Vantha Posted 9 hours ago Report Share Posted 9 hours ago That's not possible, unfortunately. Essentially, the engine creates different JS script interfaces for different purposes - one for the GUI (scripts in gui/), one for the simulation (scripts in simulation/ and trigger scripts in maps/scenarios/) and one for map generation (scripts in maps/random/). And those Engine functions are always registered in specific contexts. Engine.QueryInterface, for example, is obviously only available in simulation context, since that's were simulation components and interfaces are. Similarly, Engine.SetSimRate and Engine.GetSimRate are only registered in the GUI scripting context, meaning you can only call them from GUI scripts. What exactly are you trying to achieve? There are some possible workarounds because the engine allows you to communicate between contexts and modifying the engine to register SetSimRate and GetSimRate in simulation scripting context too is quite straightforward actually. Quote Link to comment Share on other sites More sharing options...
CulturedCait Posted 4 hours ago Author Report Share Posted 4 hours ago Hi Vantha, thanks for detailed explanation. All is clear now. What I wanted to achieve is to programmatically speed up the game in the beginning to the value of~ x20 (just temporarily) to override default Map Setup setting. Reason is to perform some JS asynchronous calculations much faster eliminating internal tick bottleneck. Then go back to the default speed value few moments after. What you described as a workaround sounds very promising! Can you please explain little more how to communicate between different contexts to register SetSimRate? Thank you! Quote Link to comment Share on other sites More sharing options...
phosit Posted 2 hours ago Report Share Posted 2 hours ago Trigger-scripts are executed in the simulation js-interface. I took a look at the tutorial and saw that it uses Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification(...); to send a message to the gui. The gui receives the messages in "session/messages.js". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.