I'm messing around with a game idea, just for fun, and I'm doing it in html5's canvas and javascript, simply because I want the practice while I'm fooling around.
In my game there are many things that will happen one at varying times, and new things to do are constantly created. Precision is not necessary, as long as it's within a few seconds.
My first idea was simply to have an array, who was manually sorted, by inserting the new tasks based on their execution time, I would then have a function set on a timeout, it would grab the new task, handle it, get the time of the next ask in line, and wait with a timeout, when a new item is added it would check to see if it was the new first in line, and change the timeout appropriately.
But then I began to wonder.... What would be the pitfalls of setting many timers? At first I had thought it'd be a bad idea to set many timers, but then I began to wonder if maybe the browser handles the times in the same way I stated above, or some other effecient way.
So basically, to summarize my concerns:
- What are the issues with using multiple timeouts, vs just doing one after another.
- Are there any pitfalls to this sort of method? Or any "Gotchas"