Class Message

Object
   |
   +--Message

class Message


Communication between the this client 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 multiplayer API automatically detects those attributes, and ensures that they get sent to the server. 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!";
multiplayer.game.lobby.sendMessage(message);
The server would then receive that message and be able to access its contents as an object. For example:
function onMessageReceived(event)
{
    //Prints out "Hello World!"
    game.log(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
 Object from
          This attribute is automatically set to the player's username before the message is sent.
 
Constructor Summary
Message ()
            Creates a new Message.
 
Method Summary
 String toString()
           Returns "[Object Message]".

Field Detail

from

Object from

Constructor Detail

Message

Message()
Method Detail

toString

String toString()