How to do it in a script, wait * seconds, or every * seconds

0 favourites
  • 8 posts
From the Asset Store
Like tourists, Travel around the world as fast as you can!
  • I tried setinterval and settimeout and they didn’t work.

    Any suggestions。

  • He’s still run every tick

  • You can use

    function waitForMillisecond(ms) { return new Promise(res => setTimeout(res, ms)); }
    
    console.time()
    console.log("Wait 1000 milliseconds");
    await waitForMillisecond(1000);
    console.log("Waited");
    console.timeEnd();
    
    function repeatEveryMillisecond(f, ms) { return new Promise(res => setInterval(f, ms)); }
    
    repeatEveryMillisecond(() => {console.log(Math.random())}, 1000);
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use

    > function waitForMillisecond(ms) { return new Promise(res => setTimeout(res, ms)); }
    
    console.time()
    console.log("Wait 1000 milliseconds");
    await waitForMillisecond(1000);
    console.log("Waited");
    console.timeEnd();
    

    > function repeatEveryMillisecond(f, ms) { return new Promise(res => setInterval(f, ms)); }
    
    repeatEveryMillisecond(() => {console.log(Math.random())}, 1000);
    
    

    thank you for your answer!!!

  • > You can use

    >

    >

    > > function waitForMillisecond(ms) { return new Promise(res => setTimeout(res, ms)); }
    > 
    > console.time()
    > console.log("Wait 1000 milliseconds");
    > await waitForMillisecond(1000);
    > console.log("Waited");
    > console.timeEnd();
    > 

    >

    >

    >

    > > function repeatEveryMillisecond(f, ms) { return new Promise(res => setInterval(f, ms)); }
    > 
    > repeatEveryMillisecond(() => {console.log(Math.random())}, 1000);
    > 
    > 

    waitForMillisecond It’s working really well

    But repeatEveryMillisecond() It didn’t work out. Still waiting for * s, then every tick run

  • Just tested this:

    function repeatEveryMillisecond(f, ms) { return new Promise(res => setInterval(f, ms)); }
    
    repeatEveryMillisecond(() => {
     const now = new Date(Date.now());
     console.log(`${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`);
    }, 5000);
    
  • Just tested this:

    > function repeatEveryMillisecond(f, ms) { return new Promise(res => setInterval(f, ms)); }
    
    repeatEveryMillisecond(() => {
    const now = new Date(Date.now());
    console.log(`${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`);
    }, 5000);
    

    Thank you!!!

    It works in the browser.

    But execute this function in C3 tick(). He’s not functioning properly.

  • What do you mean by "tick execution"?

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/iruntime: "tick" by definitions fires every tick.

    I expect a "setInterval" command repeated on every tick to become equivalent to executing the same command on every tick.

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