How do asynchronous functions work?

0 favourites
  • 3 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • I don't understand why in this case there's a freeze for a few seconds:

    I expected that enabling the "asynchronous" option would allow the function to run in parallel with the main thread. Similar to how the "Find path" action works with the "Pathfinding" behavior. That is, the action starts the pathfinding process in parallel with the main thread, which avoids performance loss.

    What should I do if I need to create a heavy function that can run for several seconds and I don't want to get the game process frozen for that time while the function is running?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Asynchronous functions simply have the benefit of being able to use "wait for previous actions to complete" so you can do a bunch of stuff inside that function like tweens and wait for all of them complete before you do the next thing.

    A heavy function like that in Construct will simply attempt to run inside a single tick, that's why there's a freeze. You might have to split this up to avoid the freezing, like adding 1000000 per tick over the course of 100 ticks. Which takes a little over 1.5 seconds to complete at 60 fps. I don't think there's a construct build-in way to do this.

  • For multithreading you can use web workers, there is an example project for it too: https://editor.construct.net/#open=scripting-web-worker

    But in my tests the cost of messaging really made the performance gains minimal or even made performance worse, so it ends up not being worth the additional complexity in most situations. You can probably make it work much better by using sharedArrayBuffers, but that doesn't tend to be supported well or at all on platforms like itch.io, scirra arcade(?) etc.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)