HTML5 (Javascript) Client Reference
Class 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 | ||||
---|---|---|---|---|
|
||||
|
||||
Methods | ||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
message.length
|
The number of entries in this message
message.type
|
The type of the message
message.add
|
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
|
Add a boolean value to the message
Arguments
value:bool | |
The bool to add |
message.addByteArray
|
Add a byte array value to the message
Arguments
value:byte[] | |
The byte array to add |
message.addDouble
|
Add a value encoded as a double to the message
Arguments
value:number | |
The number to add |
message.addFloat
|
Add a value encoded as a float to the message
Arguments
value:number | |
The number to add |
message.addInt
|
Add a value encoded as an int to the message
Arguments
value:number | |
The number to add |
message.addLong
|
Add a value encoded as a long to the message
Arguments
value:number | |
The number to add |
message.addString
|
Add a string value to the message
Arguments
value:string | |
The string to add |
message.addUInt
|
Add a value encoded as a uint to the message
Arguments
value:number | |
The number to add |
message.addULong
|
Add a value encoded as a ulong to the message
Arguments
value:number | |
The number to add |
message.getBoolean
|
Get the bool from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getByteArray
|
Get the int from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getDouble
|
Get the double from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getFloat
|
Get the float from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getInt
|
Get the int from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getLong
|
Get the long from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getString
|
Get the string from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getUInt
|
Get the uint from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.getULong
|
Get the ulong from the message at the given index
Arguments
index:int | |
The zero-based index of the entry to get |
message.toString
|
Get a string representation of the message