Can I add Javascript code that continually loops in the background?

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • I am working on a Construct program that includes some open source Javascript code. (To communicate with a Bluetooth device.)

    Part of the open source Javascript code runs in a loop every 100ms. What would be the best way to do this using Construct?

    Should I create a loop in Construct that calls the Javascript code every 100ms? Would this be reliable, or would the timing get off?

    Alternately, is there a way to do the looping in Javascript while Construct is still running?

    Here is how the Javascript code is structured:

    const timer = window.setInterval(()=> {
    		
    	(code...)
    
     }, 100);
    
  • I believe you can just put this script into "On start of layout" event. It will repeat every 0.1s

    But this will not work with Worker enabled. If you need Worker, perhaps you should run this script using "Every 0.1 seconds" event or Timer behavior.

  • Thank you for the reply! I'm not sure what Worker does so I'll do some research on that. Yeah, it sounds like I might be able to use a Construct timer to run the script. I'll give that a try.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • FWIW, setInterval can be used in workers too, but window is not defined in workers. You should follow the advice to always refer to the global object with globalThis instead of window to avoid such problems.

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