Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 arrays of JSON objects, actions and game objects.

At any time a user can make a request from the client which can add an action to the actions array.

I have a setInterval(function(){ }, 1000); that runs every second and first loops through all of the actions, doing them in order then dumping emptying the array. Then it for loops (on the length of the array) through all the objects and does change processing such as healing, repairing, consuming resources, updating location of travelling objects, etc.

Each game object is tied to a user and when it is done being modified it will push out to them using all the data they need for their current view (assuming they are in an active session still).

Is this right? Am I not taking advantage of the node.js event loop as well as I could for this?

share|improve this question
That depends on type of game, if you have game that is entirely event based (like tick tack toe) or something that can be made to look like event based (storing when action is going to finish, and finish it after someones query it - this could work for stuff like cooldown for spells, but not healing after time) Then you can have everything based just on events. If you have realtime game, like mmorpg, you need that loop. Btw when using setInterval like this will not work when time to process everything will be bigger then 1000. – Kikaimaru Dec 23 '12 at 18:05
Healing over time with a delay can totally be query/event driven. If you can make a function to calculate absolute given an input of elapsed time, all you need is to store the previous value and the it was calculated at. – Sean Middleditch Oct 4 '13 at 21:29
up vote 2 down vote accepted

It's better to use setImmediate() or process.nextTick() for game loop. setImmediate vs. nextTick

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.