Event

Events are useful to establish communication between the Server and all connected Players.

Here's a simple example:

local e = Event()
e.someMessage = "Something I'd like to say!"
e.someNumber = 42
e:SendTo(Server) -- send to Server

-- other possible recipients:
e:SendTo(Players) -- send to all players
e:SendTo(Players[2]) -- send to player 2
e:SendTo(OtherPlayers) -- send to all players but self

Events trigger the DidReceiveEvent function for each recipient (see Client.DidReceiveEvent & Server.DidReceiveEvent).

Server.DidReceiveEvent = function(event)
  -- `action` here is a custom field set by the developer
  if event.action == "ping" then

    local response = Event()
    response.action = "pong"
    response:SendTo(event.Sender)

  end
end

Constructors

Event ( )

Creates an empty event.

Custom fields can then be set with string, number and boolean values. (more value types will be supported soon)

local e = Event()
e.someMessage = "Something I'd like to say!"
e.someNumber = 42
e:SendTo(OtherPlayers)

Functions

Sends the Event to recipients in parameters.

Recipients can be individual Players, OtherPlayers, Players or Server.

local e = Event()
e.someMessage = "Something I'd like to say!"
e:SendTo(Player[2], Player[3]) -- send to player 2 & 3

Properties

array Recipients read-only

An array containing all recipients for that event.
Recipients can contain individual Players, OtherPlayers, Players or Server.

Server or Player Sender read-only

Who sent the event. A useful property when you want to send a response:

Server.DidReceiveEvent = function(event)
  -- `action` here is a custom field set by the developer
  if event.action == "ping" then

    local response = Event()
    response.action = "pong"
    response:SendTo(event.Sender)

  end
end