Class Message

Object
   |
   +--Message

class Message


Communication between the various clients on the internet and your server code is handled almost entirely by passing messages back and forth. Messages are passed in the form of Javascript objects containing whatever information you wish to attach to the object.

Information is attached to Message objects by simply setting an attribute on the object. The WiiCade server automatically detects those attributes, and ensures that they get sent to the client. For example, if you wanted to pass a message saying "Hello World!", you might create an object like this:

var message = new Message();

message.text = "Hello World!";
player.sendMessage(message);
The client would then receive that message and be able to access its contents as an object. For example:
function onMessageReceived(event)
{
    //Prints out "Hello World!"
    trace(event.message.text);
}
The most important thing to understand is that the contents of messages are completely controlled by your code. You can pass any attributes you want, of any type you want. This includes the ability to nest objects and arrays. The only datatype that is forbidden is embedding Javascript functions into a message.

The contents of a message can be explored by using a "for(var in message)" loop. For example, the following code will print out the current contents of a message:
for(var i in message)
{
    game.log(i + "=" + message[i]);
}

Defined in Message.js


Field Summary
 Number timestamp
          Reserved for future use.
 
Constructor Summary
Message ()
            Creates a new Message.
 

Field Detail

timestamp

Number timestamp

Constructor Detail

Message

Message()