This section covers several Lua based functions and actions performed withing the Table Realms Designer, along with a brief description of what they do and how to implement them. Please note, this section is a work in progress, and any suggestions can be submitted to the Table Realms forums.
SendAction(model.id .. ".StartGame")
This function is used to send actions to the host device. The actions fire events differently according to the platform you are using to develop your game.
In order for it to operate correctly, there needs to be a matching action on the TableRealmsPlayerActionBehavior object. For the “StartGame” action, the matching action would be:
public void StartGame() {}
Actions in Construct work differently to other develoment platforms. When using construct, you need to create an event block that receives the command and interprets the instruction. It would look similar to this:
| Object for Event | Condition | Parameters | Object for Action | Action | Parameters |
|---|---|---|---|---|---|
| Table Realms | Action executed named | “start” | Table Realms | send command | “gameStarted”=“” |
| Table Realms | Command Received named | “gameStarted” | TableRealms | Set String | “page”=“Game” |
SendAction can be called from the lua or in the script field on a button, displayed in the image below.
The script field on a button can also call a function in the Lua, such as start().
To check if the model changed we need to perform the following actions:
gameData={}
gameData.thing=""
function CheckModelChanged()
if gameData.thing~=model.thing then
gameData.thing=model.thing
DoStuff()
end
end
AddModelListener("leader.0.id", function(key, value) LeaderChanged(key, value, 1) end)
AddTickHook(CheckModelChanged)
Set things into the model the same way as they are set into the gameData above.
Note: The model is a Lua table that contains all the relevant data for both the game and players. It is shared between players.
The Players.lua package introduces new functions to assist with player management by listening to changes to model.players, and then breaking those changes into players leaving and joining the game. Calling callbacks for each event.
AddPlayersAddedListener(function(playerId)
print("Added Player:" .. playerId)
end
)
AddPlayersRemovedListener(function(playerId)
print("Removed Player:" .. playerId)
end
)
In order for the values of named components to be “get” and “set”, at least one of the components on a page needs to be named. Then, the following actions can be performed:
"components.[name]" in Lua.components.[name].text = "abc123"In Lua, you can talk to the environment to perform actions such as:
environment:Close()environment:EndHostSession()environment:SetOnlineModelKeys({"MySoloHighScore","MyTeamHighScore"})A function to assist with splitting strings string.split can be used as follows:
local str="Items,More,OtherThings"
local items=string.split(str,',')
print(table.tostring(items))
-- output
{
"Items",
"More",
"OtherThings"
}