Thursday 8 June 2017

nodejs setinterval convert to real time

I am building small multiplayer game and iam having hard time to grasp setInterval configuration. Lets say that i want to give players abilities that will run on cooldown or spawn certain objects in actual time interval (like every 5 seconds or have 2 seconds cool down). The problem is that I cannot sync server setInterval loop with real time concept.

for example i have this loop that runs cooldowns:

setInterval(function() {
    game.mechanics.buffered.cooldowns.run();
}, 10);

I have notices that if I lower this 10 value, cooldowns run faster, if i put it to higher number, they run slower, but i have no idea how to sync it for real time. I dont even know what value should be put there in server loop in the first place, i am happy with 10ms so far but real time cooldowns wont work with it currently.

Logic points that setTimeout would be more proper solution for spawning and such but setInterval gives me possibility of providing progress bar while setTimeout does not.

The question would be, how to properly configure this loop so then i can say in cooldown object that it lasts 2 seconds and it will be executed after those 2 seconds.



via P.K.

No comments:

Post a Comment