Module net_match

Represents an individual internet multiplayer game.

You should never construct this object yourself. It comes from Net matchmaking.

NetMatch extends BoundObject

Properties

player_count (readonly) The number of players in the match.
player_number (readonly) The assigned player number of the local player.

Instance Methods

net_match:handshake () Begin the player handshake process.
net_match:get_metadata () Fetch metadata for all the players in the match.
net_match:handshake (to, kind, payload) Send a message to one or all players of the NetMatch.

Hooks

all_ready (self) Called once all players have informed each other of their player numbers.
got_metadata (self, metadata) Called when metadata for players has been retrieved in response to get_metadata.
got_metadata (self, from, kind, payload) Called when a message is received from another player.

Constants

MSG_NULL A null message kind.
MSG_PACKED_RECORDER A message kind that contains a Recorder in the payload.
MSG_JSON A general-purpose JSON message.


Properties

Properties. Significant fields on an instance.
player_count
(readonly) The number of players in the match.
player_number
(readonly) The assigned player number of the local player.

Instance Methods

Instance Methods. Must be called on an instance of Class. e.g. instance:method("foo")
net_match:handshake ()
Begin the player handshake process. This process assigns each player in the match their player_number . When all players have been assigned, the all_ready hook is called.

Returns:

    nil
net_match:get_metadata ()
Fetch metadata for all the players in the match. When the metadata is retrieved, the got_metadata hook is called.

Returns:

    nil
net_match:handshake (to, kind, payload)
Send a message to one or all players of the NetMatch.

Parameters:

  • to number The player number to send the message to. If you pass 0, the message will be sent to all players.
  • kind number The kind of message to be sent. This may incur additional type checking for the payload
  • payload The contents of the message to be sent. This will be different depending on the kind of message being sent.

Hooks

Hooks. Callbacks implemented in subclasses to customize behavior. Hooks are called on individual instances.
all_ready (self)
Called once all players have informed each other of their player numbers.

Parameters:

  • self NetMatch The NetMatch instance
got_metadata (self, metadata)
Called when metadata for players has been retrieved in response to get_metadata. This returns metadata with the following structure:

 {
     {
         "display_name" = "foo",
         "alias" = "bar"
     },
     ...
 }

The player metadata in the array is indexed by the corresponding player numbers.

Parameters:

  • self NetMatch The NetMatch instance
  • metadata table An array of player metadata
got_metadata (self, from, kind, payload)
Called when a message is received from another player.

Parameters:

  • self NetMatch The NetMatch instance.
  • from number The player number of the player who sent the message.
  • kind number The kind of the received message.
  • payload The payload of the message.

Constants

Constants. Accessed at the class level e.g. Class.CONSTANT
MSG_NULL
A null message kind. Doesn't contain any data.
MSG_PACKED_RECORDER
A message kind that contains a Recorder in the payload.

Sending: Provide a Recorder instance in the payload.

Receiving: A new Recorder instance. It still needs to be added to a Scene and assigned an Entity.

MSG_JSON
A general-purpose JSON message.

Sending: Will encode payload into JSON.

Receiving: Will decode the JSON and pass the decoded object as the payload.

generated by LDoc 1.3.12