PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) message class informationClass message

Language: Javascript (HTML5)

Represents a message sent between client and server. A message consists of a string type, and a payload of zero or more typed parameters.

Example

This is how to create a simple message that we send to the server indicating that this player is ready:

Example

Usually, it's much easier to simply use the convenience methods:

Example

You can also build up messages as you go, if you don't know the exact payload until runtime. In this example, imagine the player has multiple pieces and we send in the list of moves this player wants to do in a single turn.

Properties

 
length :int

The number of entries in this message

type :string

The type of the message

Methods

 
add (arguments):

Adds data entries to the Message object

addBoolean (value):

Add a boolean value to the message

addByteArray (value):

Add a byte array value to the message

addDouble (value):

Add a value encoded as a double to the message

addFloat (value):

Add a value encoded as a float to the message

addInt (value):

Add a value encoded as an int to the message

addLong (value):

Add a value encoded as a long to the message

addString (value):

Add a string value to the message

addUInt (value):

Add a value encoded as a uint to the message

addULong (value):

Add a value encoded as a ulong to the message

getBoolean (index):

Get the bool from the message at the given index

getByteArray (index):

Get the int from the message at the given index

getDouble (index):

Get the double from the message at the given index

getFloat (index):

Get the float from the message at the given index

getInt (index):

Get the int from the message at the given index

getLong (index):

Get the long from the message at the given index

getString (index):

Get the string from the message at the given index

getUInt (index):

Get the uint from the message at the given index

getULong (index):

Get the ulong from the message at the given index

toString ():

Get a string representation of the message

message.length

length :int

The number of entries in this message

message.type

type :string

The type of the message

message.add

add (arguments):

Adds data entries to the Message object

Arguments

arguments:
Entries to add. Valid types are Number, String, Boolean and ByteArray. If a Number is passed, and it is an integer, it will be added to the first type it fits in this order: Int, UInt, Long, ULong. If it doesn't fit in any integer type, or if it's not an integer, it will be added as a Double.

Example

How to add values to a message

message.addBoolean

addBoolean (value):

Add a boolean value to the message

Arguments

value:bool
The bool to add

message.addByteArray

addByteArray (value):

Add a byte array value to the message

Arguments

value:byte[]
The byte array to add

message.addDouble

addDouble (value):

Add a value encoded as a double to the message

Arguments

value:number
The number to add

message.addFloat

addFloat (value):

Add a value encoded as a float to the message

Arguments

value:number
The number to add

message.addInt

addInt (value):

Add a value encoded as an int to the message

Arguments

value:number
The number to add

message.addLong

addLong (value):

Add a value encoded as a long to the message

Arguments

value:number
The number to add

message.addString

addString (value):

Add a string value to the message

Arguments

value:string
The string to add

message.addUInt

addUInt (value):

Add a value encoded as a uint to the message

Arguments

value:number
The number to add

message.addULong

addULong (value):

Add a value encoded as a ulong to the message

Arguments

value:number
The number to add

message.getBoolean

getBoolean (index):

Get the bool from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getByteArray

getByteArray (index):

Get the int from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getDouble

getDouble (index):

Get the double from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getFloat

getFloat (index):

Get the float from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getInt

getInt (index):

Get the int from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getLong

getLong (index):

Get the long from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getString

getString (index):

Get the string from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getUInt

getUInt (index):

Get the uint from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.getULong

getULong (index):

Get the ulong from the message at the given index

Arguments

index:int
The zero-based index of the entry to get

message.toString

toString ():

Get a string representation of the message