Core Plugin Expressions

Table Realms Expressions:

Event Expressions

GetActionExecutedName

Provides the name of the last action that was called

GetActionExecutedValue

Provides the value of the last action that was called into the model

GetCommandReceivedName

Provides the name of the last command that was received

GetCommandReceivedValue

Provides the string value of the last command that was received by the device

GetModelChangedKey

Provides the name of the last model key that was changed

GetPlayerJoinedID

Provides the ID of the last player that joined

GetPlayerLeftID

Provides the ID of the last player that left

GetQRUrl

Used as an expression to set the URL for the game’s QR code, when setting the image for a Sprite Object from a URL.

Model Expressions

GetDeviceID

Gets the ID of the device on which a specific instance of the game is running

GetDouble

This allows you to receive the numerical value for a specific key in the model

GetNthPlayerId

Provides the ID of a particularly numbered player. Note, the order of thi list might vary between games.

GetPlayerCount

Gets the number of players connected to the current Table Realms session. Can be used to trigger certain threshold actions, such as enabling or disabling context sensitive buttons.

GetString

This allows you to receive the string value for a specific key in the model


Conditions

Context

The different options available under “Context” can be used both as conditions and as identifiers. Using each of the options determines which mode the game is running as, and whether the instance of the game is currently running as a client or a host.

The context can then be used as a trigger to fire various events. An example of this would be checking whether the game is running in P2P mode, in which case, the QR sprite will be rendered invisible.

It is important to wrap everything in the context options of “is this instance a client” or “is this instance a host”. This will allow the P2 architecture model to be followed correctly, with anything that influences the outcome of the game being handled by the host. The different context options available are as follows:

Are we running as P2P

This returns true if the game is running in P2P mode.

Are we running as Embedded

This returns true if the game is running in Embedded mode

Are we running in Console Mode

This returns true if the game is running in Console mode

Is this instance a client

This returns true if the device is running as a client. Always true for all mobile devices when running in console mode.

Is this instance a host

This returns true if the device is running as the host. Always true for the console when console mode is being run.

QRCode data ready

True when the QR code data is ready to be loaded into a URL. Can be used as a condition to populate the QR code image, if there is no Lobby system being used.


Safely Using the P3P Model

The P3P model might seem like it requires less planning upfront, but in reality the reverse is true. When using the P3 architecture in Construct, a device needs to take responsibility for synchronisations. What this means is that some data needs to “belong” to the host, and some data needs to “belong” to the client(s). In this case, they should only be able to set model data from a single source. If model data is set concurrently from multiple sources, the devices will be in an asynchronous state, thereby causing a Table Realms crash.

The above point is important to remember since Table Realms does not enforce ownership of model data. In P3P, the client has the ability change any data. Ideally the client should only ever change the client’s information or data that is specificly meant to be changed by the client. A developer could choose to identify client owned information any way they want, but a good practice would be to use the device ID to do so. Note the inclusion of device id to the public key in the below event blocks. The “getDeviceId” function will only return the embedded device’s ID. Ensure that you use an “are we embedded” check when using getDeviceId, because this only works in embedded.

Object for Event Condition Parameters Object for Action Action Parameters
TableRealms Are we embedded TableRealms Set Double “publicDataKeyNumber.” & TableRealms.GetDeviceID=20
-> System On start of layout TableRealms Set String “publicDataKey.” & TableRealms.GetDeviceId=“This is data that was set privately by device id ” & TableRealms.GetDeviceId
-> System On start of layout TableRealms Set String “publicDataKeyNumber.” & TableRealms.GetDeviceID=20

Events

The following conditions are used when determining whether to fire triggers for events:

Action Executed Any

This trigger is fired when any action is executed.

Action Executed Named

This trigger is fired when a specific action being executed. You can specify which action by entering the name of the action being executed in the dialog box that appears.

Command Received Any

This trigger is fired when any command is received by the client or host device.

Command Received Named

This trigger is fired when a specific command is received by the device. You can specify which command to listen for by entering the name of the command being sent in the dialog box that appears.

Model Changed Any

This trigger is fired when there is a change to any value in the model.

Model Changed Key

This trigger is fired when there is a change in the model value linked to a specific key. This is specified by entering the name of the key whose value you want to track in the dialog box that appears.

Player Joined

This trigger is fired when a player joins the session.

Player Left

This trigger is fired when a player leaves the session.

Started

This trigger is executed when Table Realms has started and is ready for use.


Actions

General

Send Command

Used by the host to distribute commands to the peers/clients. The command being sent needs a specific name and string parameter.

Model

Set Double

This allows you to set the numerical value for a specific key in the model

Set String

This allows you to set the string value for a specific key in the model