whigmal
10 months agoMHCP Member
Typescript Async setInterval issue?
Let's say I have an async interval call like so:
this.async.setInterval(()=>{
console.log(player.name.get())
},1000)This code works as intended within the TypeScript environment.
However, the moment I add a variable to capture the timeout ID as mentioned in the documentation:
/**
* Sets a timer which executes a function or specified piece of code once the timer expires.
* @param callback - A function to be compiled and executed after the timer expires.
* @param timeout - The time, in milliseconds that the timer should wait before the specified function or code is executed.
* If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.
* @param args - Additional arguments which are passed through to the function specified by callback.
* @returns The timer created by the call to `setTimeout()`.
* This value can be passed to `clearTimeout()` to cancel the timeout. It is guaranteed that a timeoutID value will never be reused
* by a subsequent call to setTimeout() or setInterval() on the same object (a window or a worker).
*/With this code:
id = this.async.setInterval(()=>{
console.log(player.name.get())
},1000)It no longer runs the async interval function and only returns the interval ID. There doesn't seem to be a way to run an interval solely off an interval ID.
Code with side effects is supposed to run regardless. In C, `printf` in an if statement will still run. For example:
#include <stdio.h>
if(printf("Hello")<0){
// error handle
}(slightly similar to Let* implicit progn in Common Lisp as well)
You're listening to OnPlayerEnterTrigger twice instead of exit. Tripped me up at first too.