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

Just as I was told here, I need to make some kind of communication between objects in my game. Mainly, for achievements. How do I do this? My idea was to make every object have an array attached to itself called "messages", and then, when something happens, a message gets pushed there. At the end, I would have a big loop, where I would check messages that each object got, remove them, and act accordingly. I could also have a global array called "messages", and then I would iterate through it, and fire off events in different objects that the messages were sent to (in this case, a message would contain both a message, and some kind of an object ID), and then remove them. Is there a better way? Keep in mind that I'm working in Javascript.

I forgot to mention, we're talking about serverside Javascript running on Node.js, not in a browser.

share|improve this question
up vote 2 down vote accepted

Why don't you just register events?

Different objects act upon events they listen to, and you can attach some datas to these events (an object like {key: 'value', key2: 'value2'}, for example).

If basic events (click, change, etc) don't satisfy you, you can register custom events. An example of how to do this here :

Edit : heh, even easier in Node.js ! There is an event module available. Look at this link :

share|improve this answer

JavaScript already uses events internally, so you could leverage that system for your game messages. While there's apparently a W3C specification for custom events, it isn't really supported in all browsers.

Here's an article that explains a possible implementation of custom events. On the other hand you could simply use a framework like YUI, which has custom events implemented and ready to use.

share|improve this answer
I forgot to mention thta I'm working on Node.js, not in a browser... – jcora Feb 17 '12 at 10:11

This calls for the Observer Pattern! Seems like Node.js already has something like it, called an EventEmitter. A similar question was asked in the Programmers StackExchange.

Hopefully this will start you on the right track!

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.