Async SetInterval Issue (spawned asset)
I'm trying to have a loop on a spawned object. When it's spawned it's sent and receives:
const spawnAssetEvent = new CodeBlockEvent<[player: Player]>('setup', [PropTypes.Player]);
I've connected it and stored the player:
this.connectCodeBlockEvent(this.entity, spawnAssetEvent, (player: Player) => {
this.player = player;
console.log(`Player ${this.player.name.get()} received spawnAssetEvent`);
this.initialize();
});
My issue is as follows:
this.async.setInterval(() => {
this.worldtick(); }, 3000);I have several methods using this.player. The setInterval loop when placed in start() will do the loop but because the player isn't yet assigned by the spawnAssetEvent it errors out with:
Error Executing Async Callback:
TypeError: Cannot read properties of undefined
placing the setInterval inside the connectCodeBlockEvent to assure the player is assigned before the loop starts doesn't fire because it's "not part of the lifecycle".
I've checked out the other SetInterval Issue on the forum but am still having issues. Any help would be greatly appreciated.
