### Example `bootexec.cfg`
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
This example `bootexec.cfg` demonstrates hosting a game, loading a saved game, switching to the system console, and activating the spectator window.
```bash
# Host a game for 8 players using default server name and password
host_game 8
# Load game on row 4 slot 5
ui_games_click 4 5
# Switch to system console
chat_tab_system
# Activate spectator window
+spectator_window
```
--------------------------------
### Standard Button Examples
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/inputelements.md
Use these examples to create standard buttons, buttons with icons, or buttons with both icons and text.
```xml
```
```xml
```
```xml
```
--------------------------------
### Example `autoexec.cfg`
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
This example `autoexec.cfg` shows creating aliases for camera commands, setting configuration options, and binding camera follow functionality to a key.
```bash
# Make easier to type versions of spectator_camera_ commands.
# i.e. cam_load instead of spectator_camera_load
alias cam_* spectator_camera_*
# Set some settings
+cam_stay_upright
-spectator_show_ui
# make right control have camera follow player while held
```
--------------------------------
### Install Project Dependencies with Pipenv
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/README.md
Installs all necessary project dependencies using Pipenv. Ensure Pipenv is installed and a Pipfile exists in the project root.
```bash
pipenv install
```
--------------------------------
### Color Manipulation Examples
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Examples demonstrating how to manipulate colors, such as interpolating between colors, adjusting brightness, and applying them to scene objects.
```APIDOC
## Manipulation Examples
### Tint all objects in scene in orange.
```lua
function onLoad()
local red = Color.Red
local green = Color.Green
-- Get a color between red and green
local yellow = red:lerp(green, 0.5)
-- Make the color brighter
yellow:set(yellow.r * 1.5, yellow.g * 1.5, yellow.b * 1.5)
-- Get a color between yellow and red
local orange = yellow:lerp(Color.Red, 0.5)
-- Iterate through all scene objects and set the color tint to orange
for k, obj in pairs(getObjects()) do
obj.setColorTint(orange)
end
end
```
### Tint all objects in a random color.
```lua
function onLoad()
-- Iterate through all scene objects and generate a random color
for k, obj in pairs(getObjects()) do
local colorA = getRandomColor()
local colorB = getRandomColor()
color = colorA:lerp(colorB, math.random(0, 1))
-- Make the color darker or brighter
local factor = math.random(1, 2)
color:set(color.r * factor, color.g * factor, color.b * factor)
-- Apply the color to object
obj.setColorTint(color)
end
end
function getRandomColor()
local r = math.random(0, 255)
local g = math.random(0, 255)
local b = math.random(0, 255)
return Color(r / 255, g / 255, b / 255)
end
```
```
--------------------------------
### onSearchStart
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a player starts searching the script-owner Object.
```APIDOC
## onSearchStart player_color
### Description
Called when a player starts searching the script-owner Object.
### Parameters
#### Path Parameters
- **player_color** (String) - Description not available
```
--------------------------------
### onObjectSearchStart
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a search is started on a container.
```APIDOC
## onObjectSearchStart
### Description
Called when a search is started on a container.
### Parameters
#### Path Parameters
- **object** (object) - Required - The container object.
- **player_color** (string) - Required - The color of the player who started the search.
```
--------------------------------
### Color Table Example (White)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Defines an RGB color value for tinting. This example shows a white color using letter keys.
```lua
{
r=1, g=1, b=1,
1=1, 2=1, 3=1,
}
```
--------------------------------
### Get Object Bounds Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Retrieves and displays the bounding box information for an object. This includes the center, size, and offset of the bounding box in global terms.
```Lua
-- Example returned Table
{
center = {x=0, y=3, z=0, 0, 3, 0},
size = {x=5, y=5, z=5}, 5, 5, 5},
offset = {x=0, y=-1, z=0, 0, -1, 0}
}
```
--------------------------------
### Get VR Command Help
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vr.md
Type 'help vr' in the console to get a summary of all available VR commands. Use 'help ' for specific information on a particular command.
```plaintext
help vr
```
```plaintext
help
```
--------------------------------
### startLuaCoroutine
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/base.md
Starts a Lua coroutine.
```APIDOC
## startLuaCoroutine(function_owner, function_name)
### Description
Start a coroutine.
### Parameters
#### Path Parameters
- **function_owner** (object) - Required - The owner of the function.
- **function_name** (string) - Required - The name of the function to start as a coroutine.
### Return
- **boolean** - Indicates success or failure of starting the coroutine.
```
--------------------------------
### Color Dump with Prefix
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Shows how to get a string description of a color, optionally with a custom prefix.
```lua
col:dump("MyColor")
```
--------------------------------
### onObjectSearchStart
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a search is started on a container. It receives the object being searched and the player's color.
```APIDOC
## onObjectSearchStart(object, player_color)
### Description
Called when a search is started on a container.
### Parameters
#### Path Parameters
- **object** (object) - The Object which was searched.
- **player_color** (string) - Player Color of the player who triggered the function.
```
--------------------------------
### Vector Table Example (Position)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents a Vector with x, y, and z coordinates. This example shows a position with x=5, y=2, and z=-1.
```lua
{
x=5, y=2, z=-1,
}
```
--------------------------------
### HorizontalScrollView Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
Demonstrates how to use HorizontalScrollView to create a horizontally scrollable container for other layout elements.
```xml
1234
```
--------------------------------
### Get Vector Components
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vector.md
Shows how to retrieve the x, y, and z components of a Vector individually using the get() method. The sum of these components is then printed.
```Lua
vec = Vector(1, 2, 3)
x, y, z = vec:get()
print(x + y + z) --> 6
```
--------------------------------
### Panel Layout Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
Use a Panel to confine elements within a 'window'. It can also function as a LayoutGroup if padding is specified.
```xml
Text contained within Panel
```
--------------------------------
### HorizontalLayout Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
Arrange elements in a horizontal row using HorizontalLayout. Control spacing and child alignment.
```xml
```
--------------------------------
### Dropdown Basic Usage
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/inputelements.md
Example of a basic Dropdown element with options and an event handler for value changes.
```xml
```
```lua
function optionSelected(player, selectedValue, id)
print(player.steam_name .. " selected: " .. selectedValue)
end
```
--------------------------------
### Lua String Type Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents a sequence of characters.
```lua
"Hello."
```
--------------------------------
### VerticalLayout Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
Organize elements in a vertical column with VerticalLayout. Customize spacing and child alignment.
```xml
```
--------------------------------
### Get Current Background Name
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/backgrounds.md
Retrieves the name of the currently active background. No setup is required.
```lua
Backgrounds.getBackground()
```
--------------------------------
### Vector Initialization and Operation
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Creates a Vector object and performs a normalized addition operation. This example demonstrates vector manipulation.
```lua
target = Vector(1, 0, 0) + Vector(0, 2, 0):normalized()
```
--------------------------------
### Lua Player Type Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents an in-game player. See Player documentation for more info.
```lua
Player["White"]
```
--------------------------------
### getStateId()
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the current state ID (index) of an object. Returns -1 if there are no other states. State IDs start at 1.
```APIDOC
## getStateId()
### Description
Current [state](https://kb.tabletopsimulator.com/host-guides/creating-states/) ID (index) an object is in. Returns -1 if there are no other states. State ids (indexes) start at 1.
### Return
[](types.md)
```
--------------------------------
### Play Music Playback
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/musicplayer.md
Plays the currently loaded audioclip. Returns true if the player was successfully started.
```Lua
MusicPlayer.play()
```
--------------------------------
### GridLayout Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
GridLayout arranges elements in a grid. Configure spacing, cell size, and alignment to control the layout.
```xml
```
--------------------------------
### Lua Table Type Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents a container holding keys and values.
```lua
{["key"]="value", true, 5}
```
--------------------------------
### Get Custom Background URL
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/backgrounds.md
Retrieves the URL of the current custom background. Returns nil if the background is not custom. No setup is required.
```lua
Backgrounds.getCustomURL()
```
--------------------------------
### Serve MkDocs Documentation Locally
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/README.md
Starts a local development server for MkDocs to preview changes. Ensure the Pipenv environment is activated before running this command. Access the preview at http://localhost:8000.
```bash
mkdocs serve
```
--------------------------------
### Example Hit Object Table
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/physics.md
Illustrates the structure of the table returned by a successful physics cast, detailing each hit object.
```Lua
{
{
point = {x=0,y=0,z=0},
normal = {x=1,0,0},
distance = 4,
hit_object = objectreference1,
},
{
point = {x=1,y=0,z=0},
normal = {x=2,0,0},
distance = 5,
hit_object = objectreference2,
},
}
```
--------------------------------
### getFogOfWarReveal()
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets settings related to Fog of War reveal for zones.
```APIDOC
## getFogOfWarReveal()
### Description
Settings impacting [Fog of War](https://kb.tabletopsimulator.com/game-tools/zone-tools/#fog-of-war-zone) being revealed.
### Return
[](types.md)
```
--------------------------------
### onCollisionEnter Lua Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an Object starts colliding with the script-owner Object. Use this to detect the beginning of a collision and access collision details.
```Lua
-- Example Usage
function onCollisionEnter(info)
print(tostring(info.collision_object) .. " collided with " .. tostring(self))
end
```
```Lua
-- Example collision_info table
{
collision_object = objectReference,
contact_points = {
{5, 0, -2}
},
relative_velocity = {0, 20, 0}
}
```
--------------------------------
### Color Constructors and Initialization
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Demonstrates different ways to create Color objects using RGB values, RGBA values, tables, and predefined color names.
```lua
local red = Color.new(1, 0, 0)
local green = Color(0, 1, 0) -- same as Color.new(0, 1, 0)
local river = Color(52 / 255, 152 / 255, 219 / 255, 160 / 255)
local teal = Color({ r = 0.129, g = 0.694, b = 0.607})
```
```lua
local col = Color.fromString("Blue")
print(col) --> Color: Blue { r = 0.118, g = 0.53, b = 1, a = 1 }
```
```lua
local color, name = Color.Blue
print(color) -- Color: Blue { r = 0.118, g = 0.53, b = 1, a = 1 }
```
--------------------------------
### Get States Table
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Returns a table detailing the states of an object. Each state includes its name, description, GUID, ID, and associated scripts.
```Lua
-- Example returned Table
{
{
name = "First State",
description = "",
guid = "AAA111",
id = 1,
lua_script = "",
lua_script_state = "",
},
{
name = "Second State",
description = "",
guid = "BBB222",
id = 2,
lua_script = "",
lua_script_state = "",
},
}
```
--------------------------------
### Get Zones Object Occupies
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Prints a comma-separated list of GUIDs for zones an object is currently in. If the object has tags, it will only occupy zones with compatible tags.
```Lua
local guids = {}
for _, zone in ipairs(object.getZones()) do
table.insert(guids, zone.guid)
end
if #guids > 0 then
print("Object is contained within " .. table.concat(guids, ", "))
else
print("Object is not contained within any zones")
end
```
--------------------------------
### List Commands and Variables
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Use `commands`, `variables`, and `help` to list commands, variables, and their descriptions. You can filter results by providing a prefix.
```bash
commands
```
```bash
variables spectator
```
```bash
help color
```
--------------------------------
### Advanced Take Object with Callback and Force
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
This advanced example demonstrates taking an object, waiting for it to spawn, and then applying an upward force. Note that smooth movement must be disabled to apply forces, and a frame delay is needed after spawning before applying impulse.
```Lua
container.takeObject({
callback_function = function(spawnedObject)
Wait.frames(function()
-- We've just waited a frame, which has given the object time to unfreeze.
-- However, it's also given the object time to enter another container, if
-- it spawned on one. Thus, we must confirm the object is not destroyed.
if not spawnedObject.isDestroyed() then
spawnedObject.addForce({0, 30, 0})
end
end)
end,
smooth = false, -- Smooth moving objects cannot have forces applied to them.
})
```
--------------------------------
### VerticalScrollView Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/layoutgrouping.md
Demonstrates a basic VerticalScrollView containing a VerticalLayout with several Panel elements. This structure allows for vertically scrollable content.
```xml
1234
```
--------------------------------
### Insert Variables into Commands
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Enclose variables in `{` and `}` to insert their values into commands. For example, `spectator_camera_target {hovered}` sets the spectator camera target to the hovered object's GUID.
```bash
spectator_camera_target {hovered}
```
--------------------------------
### Get Joint Information
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Returns detailed information about joints attached to an object, including the GUID of connected objects and joint-specific properties like type, forces, and constraints.
```Lua
{
{
type = "Spring",
joint_object_guid = "555555",
collision = false,
break_force = 1000,
break_torgue = 1000,
axis = {0,0,0},
anchor = {0,0,0},
connector_anchor = {0,0,0},
motor_force = 0,
motor_velocity = 0,
motor_free_spin = false,
spring = 50,
damper = 0.1
max_distance = 10
min_distance = 0
},
{
type = "Spring",
joint_object_guid = "888888",
collision = false,
break_force = 1000,
break_torgue = 1000,
axis = {0,0,0},
anchor = {0,0,0},
connector_anchor = {0,0,0},
motor_force = 0,
motor_velocity = 0,
motor_free_spin = false,
spring = 50,
damper = 0.1
max_distance = 10
min_distance = 0
},
}
```
```Lua
local jointsInfo = self.getJoints()
for k, v in pairs(jointsInfo[1]) do
print(k, ": ", v)
end
```
--------------------------------
### Vector Arithmetic and Comparison Examples (Lua)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vector.md
Demonstrates basic vector arithmetic (addition, subtraction) and comparison using overloaded operators. Note that direct vector addition and subtraction create new vectors, leaving the original unchanged.
```lua
function onLoad()
local vec = Vector(1, 2, 3)
vec:add(Vector(3, 2, 1)) --> vec is now {4, 4, 4}
vec:sub(Vector(1, 0, 1)) --> vec is now {3, 4, 3}
local another = vec + Vector(-1, -2, -1) --> another is {2, 2, 2}, vec remains unchanged
print(another:equals(Vector(1, 2, 3))) --> false
print(another == Vector(2, 2, 2)) --> true
print(another == Vector(1.99, 2.01, 2)) --> true, small differences are tolerated
end
```
--------------------------------
### Get Trigger Effects - Tabletop Simulator API
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/assetbundle.md
Retrieves a table containing information about all trigger effects. Each entry includes the effect's index and name. Indexes start at 0.
```Lua
effectTable = self.AssetBundle.getTriggerEffects()
```
```Lua
{
{index=0, name="Effect Name 1"},
{index=1, name="Effect Name 2"},
}
```
--------------------------------
### Create and Manipulate Colors
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Demonstrates creating Color instances using different constructors and manipulating them. Remember to use the colon operator for member functions.
```lua
function onLoad()
local red = Color.new(1, 0, 0)
local green = Color(0, 1, 0) -- same as Color.new(0, 1, 0)
local orangePlayer = Color.fromString("Orange")
local purplePlayer = Color.Purple
end
```
```lua
function onLoad()
local col = Color(0, 0.5, 0.75)
col.r = 1 -- set the first component
col[2] = 0.25 -- set the second component
col:setAt('b', 1) -- set the third component
print(col:get()) --> same as print(col.r, col.g, col.b, col.a)
for colorCode, value in pairs(col) do
```
--------------------------------
### Get Looping Effects - Tabletop Simulator API
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/assetbundle.md
Retrieves a table containing information about all looping effects. Each entry includes the effect's index and name. Indexes start at 0.
```Lua
effectTable = self.AssetBundle.getLoopingEffects()
```
```Lua
{
{index=0, name="Effect Name 1"},
{index=1, name="Effect Name 2"},
}
```
--------------------------------
### Set UI from XML String
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui.md
Replace the entire UI with content defined in an XML string. Custom assets can optionally be provided.
```lua
UI.setXml("Test")
```
--------------------------------
### Vector Constructors and Utility Functions
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vector.md
Demonstrates the creation of Vector instances using different constructor forms and utility functions like `between`, `max`, and `min`. Note that `Vector(x, y, z)` is equivalent to `Vector.new(x, y, z)`.
```lua
function onLoad()
local vec1 = Vector.new(0.5, 1, 1.5)
local vec2 = Vector(1, -1, 0) -- same as Vector.new(1, -1, 0)
print(Vector.between(vec1, vec2)) --> Vector: {0.5, -2, -1.5}
print(Vector.max(vec1, vec2)) --> Vector: {1, 1, 1.5}
print(Vector.min(vec1, vec2)) --> Vector: {0.5, -1, -0}
end
```
--------------------------------
### Load Game State
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a saved game has finished loading or when an Object script has finished loading. This example decodes a JSON game state, accesses nested data, retrieves an object by GUID, and highlights it.
```Lua
local some_object -- We'll store an object reference to use later.
function onLoad(script_state)
-- JSON decode our saved state
local state = JSON.decode(script_state)
-- In this example, we're assuming the existence of some specific saved state data.
local questions = state.questions -- access a nested table
for _, qa in ipairs(state.questions) do
print("Question: " .. qa.question)
print("Answer: " .. qa.answer)
end
some_object = getObjectFromGUID(state.guids.some_object)
-- Let's highlight some_object a random color.
-- Because why not.
local colors = {'Blue', 'Yellow', 'Green'}
some_object.highlightOn(colors[math.random(1, 3)])
end
```
--------------------------------
### Show Options Dialog
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Use this to present a player with a dropdown list of options to choose from. The callback receives the selected text, its index, and the player's color.
```Lua
chosen_player.showOptionsDialog("Choose Value", {"1", "2", "3", "4", "5", "6"}, dice.getValue(),
function (text, index, player_color)
dice.setValue(index)
end
)
```
--------------------------------
### playTriggerEffect
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/assetbundle.md
Starts playing a specified trigger effect by its index. Indexes start at 0.
```APIDOC
## playTriggerEffect(index)
### Description
Starts playing a trigger effect.
### Method
POST (conceptual, as this is an SDK function)
### Endpoint
N/A (SDK Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **index** (int) - Required - The index of the trigger effect to play. Indexes start at 0.
### Request Example
```lua
-- Assuming 'effectIndex' is a variable holding the desired index
self.AssetBundle.playTriggerEffect(effectIndex)
```
### Response
#### Success Response (200)
- **nil** - Indicates the effect was successfully started.
#### Response Example
```json
{
"example": null
}
```
```
--------------------------------
### playLoopingEffect
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/assetbundle.md
Starts playing a specified looping effect by its index. Indexes start at 0.
```APIDOC
## playLoopingEffect(index)
### Description
Starts playing a looping effect.
### Method
POST (conceptual, as this is an SDK function)
### Endpoint
N/A (SDK Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **index** (int) - Required - The index of the looping effect to play. Indexes start at 0.
### Request Example
```lua
-- Assuming 'effectIndex' is a variable holding the desired index
self.AssetBundle.playLoopingEffect(effectIndex)
```
### Response
#### Success Response (200)
- **nil** - Indicates the effect was successfully started.
#### Response Example
```json
{
"example": null
}
```
```
--------------------------------
### Standard Toggle Examples
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/ui/inputelements.md
Create a simple on/off toggle switch. The isOn attribute can be set to true to have the toggle selected by default.
```xml
Toggle Text
```
```xml
Toggle Text
```
--------------------------------
### onObjectLeaveZone
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an object leaves a zone. It prints the GUID of the object and the GUID of the zone it left.
```APIDOC
## onObjectLeaveZone(zone, object)
### Description
Called when an object leaves a zone. It prints the GUID of the object and the GUID of the zone it left.
### Parameters
#### Path Parameters
- **zone** (Zone) - Required - Zone that was left.
- **object** (Object) - Required - The object that left.
### Request Example
```lua
function onObjectLeaveZone(zone, object)
print("Object " .. object.guid .. " left zone " .. zone.guid)
end
```
```
--------------------------------
### Lambda-Style Functions Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/lua-in-tabletop-simulator.md
Demonstrates the non-standard Lambda-Style Function syntax for callbacks and conditions. Use with caution as it's not standard Lua.
```lua
local block = spawnedBlock({
type = 'BlockSquare',
callback_function = |spawnedBlock| print(spawnedBlock.type .. " spawned")
})
Wait.condition(|| print('Block is now resting'), || block.resting)
```
--------------------------------
### onObjectLeaveContainer
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an object leaves a container. It prints the GUID of the object and the GUID of the container it left.
```APIDOC
## onObjectLeaveContainer(container, object)
### Description
Called when an object leaves a container. It prints the GUID of the object and the GUID of the container it left.
### Parameters
#### Path Parameters
- **container** (object) - Required - Container the object left.
- **object** (object) - Required - Object that left the container.
### Request Example
```lua
function onObjectLeaveContainer(container, object)
print("Object " .. object.guid .. " left container " .. container.guid)
end
```
```
--------------------------------
### UI Button for Camera Positions
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Creates UI buttons to load specific camera positions.
```bash
ui_button 1 600 0 cam_load 1
ui_button 2 600 -30 cam_load 2
ui_button 3 600 -60 cam_load 3
```
--------------------------------
### onObjectEnterContainer
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called each time an object enters a container. It prints the GUID of the object and the GUID of the container it entered.
```APIDOC
## onObjectEnterContainer(container, object)
### Description
Called each time an object enters a container. It prints the GUID of the object and the GUID of the container it entered.
### Parameters
#### Path Parameters
- **container** (object) - Required - The container the object entered.
- **object** (object) - Required - The object that entered the container.
### Request Example
```lua
function onObjectEnterContainer(container, object)
print("Object " .. object.guid .. " entered container " .. container.guid)
end
```
```
--------------------------------
### Setting Color Tint Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Converts RGB values from a 0-255 range to the 0-1 range required for setting an object's color tint.
```lua
--To display a color that is r=50, b=83, g=199
self.setColorTint({50/255, 83/255, 199/255})
```
--------------------------------
### Autoexec Script: Display Object GUID
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Displays the GUID of the currently held object, or the hovered object if no object is held.
```bash
store_text echo_guid_script
skip :held grabbed
echo {{hovered}}
exit
:held
echo {{grabbed}}
end echo_guid_script
alias echo_guid exec -q -v echo_guid_script
bind KeypadEnter echo_guid
```
--------------------------------
### Color Constructors
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Demonstrates various ways to create Color objects using the Color.new() and Color.fromString() constructors, as well as predefined color constants.
```APIDOC
## Color Constructors
### Color.new(...)
[](types.md) Return a color with specified components.
!!!info "Color.new(r, g, b)"
* [](types.md) **r**: Red component between 0 and 1.
* [](types.md) **g**: Green component between 0 and 1.
* [](types.md) **b**: Blue component between 0 and 1.
!!!info "Color.new(r, g, b, a)"
* [](types.md) **r**: Red component between 0 and 1.
* [](types.md) **g**: Green component between 0 and 1.
* [](types.md) **b**: Blue component between 0 and 1.
* [](types.md) **a**: Alpha component between 0 and 1.
!!!info "Color.new(t)"
* [](types.md) **t**: The table should use the `r`, `g`, `b` and `a` index. By default the value is 0 for color and 1 for alpha.
``` Lua
local red = Color.new(1, 0, 0)
local green = Color(0, 1, 0) -- same as Color.new(0, 1, 0)
local river = Color(52 / 255, 152 / 255, 219 / 255, 160 / 255)
local teal = Color({ r = 0.129, g = 0.694, b = 0.607})
```
!!!info
If you want to use value between 0 and 255 you should divide them by 255 before construct the object.
### Color.fromString(...)
[](types.md) Return a color from a color string ('Red', 'Green' etc), capitalization ignored.
!!!info "Color.fromString(colorStr)"
* [](types.md) **colorStr**: Any [Player Color](player/colors.md) or color added with [Color.Add](#coloradd).
``` Lua
local col = Color.fromString("Blue")
print(col) --> Color: Blue { r = 0.118, g = 0.53, b = 1, a = 1 }
```
### Color.Blue
[](types.md)
[](types.md) Return a color from a color string ('Red', 'Green' etc).
Any [Player Color](player/colors.md) or color added with [Color.Add](#coloradd).
``` Lua
local color, name = Color.Blue
print(color) -- Color: Blue { r = 0.118, g = 0.53, b = 1, a = 1 }
```
```
--------------------------------
### Apply Bright Red Lighting
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/lighting.md
Sets the light intensity and color to bright red, then applies the changes. This example demonstrates setting global lighting properties.
```lua
Lighting.light_intensity = 2
Lighting.setLightColor({r = 1, g = 0.6, b = 0.6})
Lighting.apply()
```
--------------------------------
### Create and Access Color Components
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Demonstrates creating a color and accessing its name and color values. This is useful for understanding the basic representation of colors.
```Lua
print(name) -- Blue
local color, name = Color.Red
print(color) -- Color: Red { r = 0.856, g = 0.1, b = 0.094, a = 1 }
print(name) -- Red
```
--------------------------------
### onSearchStart
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a player finishes searching the script-owner Object. It receives the player's color as an argument.
```APIDOC
## onSearchStart(...)
### Description
Called when a player finishes searching the script-owner Object.
### Parameters
#### Query Parameters
- **player_color** (Player Color) - Required - The color of the player who finished searching.
```
--------------------------------
### Method Chaining Example (Lua)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vector.md
Illustrates method chaining for performing multiple vector operations without intermediate variables. Many methods return the instance itself to enable this.
```lua
vec:setAt('y', 0):scale(0.5):rotateOver('y', 90)
```
--------------------------------
### Perform HTTP GET Request
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/webrequest/manager.md
Use this to perform an HTTP GET request. It's recommended to provide a callback function to handle the response or errors.
```lua
WebRequest.get("https://api.github.com/zen", function(request)
if request.is_error then
log(request.error)
else
broadcastToAll(request.text)
end
end)
```
--------------------------------
### onObjectEnterZone
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an object enters a zone. It prints the GUID of the object and the GUID of the scripting zone it entered. Objects with specific tags will only enter zones with compatible tags.
```APIDOC
## onObjectEnterZone(zone, object)
### Description
Called when an object enters a zone. It prints the GUID of the object and the GUID of the scripting zone it entered. Objects with specific tags will only enter zones with compatible tags.
### Parameters
#### Path Parameters
- **zone** (Zone) - Required - Zone that was entered.
- **object** (Object) - Required - Object that entered the zone.
### Request Example
```lua
function onObjectEnterZone(zone, object)
print("Object " .. object.guid .. " entered zone " .. zone.guid)
end
```
```
--------------------------------
### showHotkeyConfig
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/base.md
Shows the hotkey configuration window.
```APIDOC
## showHotkeyConfig()
### Description
Shows the hotkey configuration window under Options->Game Keys.
### Return
- **boolean** - Indicates success or failure of showing the hotkey configuration.
```
--------------------------------
### Create and Set Vector Components
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/vector.md
Demonstrates how to create a new Vector and modify its components using the set() method. The print() function shows the updated Vector values.
```Lua
vec = Vector(1, 2, 3)
vec:set(4, 3, 2)
print(vec) --> Vector: { 4, 3, 2 }
```
--------------------------------
### Get Snap Points
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Retrieve a table listing all snap points associated with an object. This function can also be called on 'Global' to get snap points on the game world's table.
```Lua
snapPoints = Global.getSnapPoints()
```
--------------------------------
### Get Color Components using get
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/color.md
Retrieves the red, green, blue, and alpha components of a color as separate values. Useful for calculations or displaying individual color channel values.
```Lua
col = Color.Blue
r, g, b, a = col:get()
print(r + g + b + a) --> 2.648
```
--------------------------------
### showConfirmDialog(info, callback)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Shows the confirm dialog to the player and executes the callback if they click OK.
```APIDOC
## showConfirmDialog(info, callback)
### Description
Shows the confirm dialog to the player and executes the callback if they click OK.
### Parameters
#### Path Parameters
- **info** (string) - Required - Information to display.
- **callback** (function) - Required - Callback to execute if they click OK. Will be called as `callback(player_color)`
### Request Example
```lua
chosen_player.showConfirmDialog("Really roll the dice?",
function (player_color)
dice.roll()
log(player_color .. " rolled the dice.")
end
)
```
```
--------------------------------
### Define Lua Functions with Parameters
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Illustrates defining a function that accepts parameters. This allows for dynamic behavior based on input values.
```Lua
function anyFuncName(printString)
print(printString)
end
```
--------------------------------
### getScale
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the current scale of the object.
```APIDOC
## getScale
### Description
Returns a Vector of the current scale.
### Return
- **Vector** - The current scale of the object.
```
--------------------------------
### showInfoDialog(info)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Shows the info dialog to the player.
```APIDOC
## showInfoDialog(info)
### Description
Shows the info dialog to the player.
### Parameters
#### Path Parameters
- **info** (string) - Required - Information to display.
### Request Example
```lua
Player.white.showInfoDialog("Only active players may floop!")
```
```
--------------------------------
### getRotation
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the current rotation of the object.
```APIDOC
## getRotation
### Description
Returns a Vector of the current rotation.
### Return
- **Vector** - The current rotation of the object.
```
--------------------------------
### onPlayerTurn
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called at the start of a player's turn.
```APIDOC
## onPlayerTurn
### Description
Called at the start of a player's turn.
### Parameters
#### Path Parameters
- **player** (player) - Required - The player whose turn it is.
- **previous_player** (player) - Required - The player whose turn just ended.
```
--------------------------------
### Autoexec Script: Private/Public Game Settings
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Sets up a toggleable variable to switch between private and public game server settings, including host name and password.
```bash
@@ # silence script
## Set up a `private_room` variable to govern whether server is private or public
# Create scripts for each mode
store_text private_game_settings
host_name Members Only!
host_password foobar
end private_game_settings
store_text public_game_settings
host_name All Are Welcome!
host_password ""
end public_game_settings
# create variable and assign scripts
store_toggle private_room
alias +private_room exec -q -v private_game_settings
alias -private_room exec -q -v public_game_settings
# bind to key, and set to private by default
bind KeypadMinus !private_room
+private_room
```
--------------------------------
### Log Layout Zone Options
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/layoutzone.md
Use this function to log the current options of a layout zone. Ensure the 'zone' object is correctly referenced.
```lua
log(zone.LayoutZone.getOptions())
```
--------------------------------
### onPlayerChatTyping
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when a player starts or stops typing.
```APIDOC
## onPlayerChatTyping
### Description
Called when a player starts or stops typing.
### Parameters
#### Path Parameters
- **player** (player) - Required - The player who is typing.
- **typing** (boolean) - Required - True if the player is typing, false otherwise.
```
--------------------------------
### getLuaScript
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Get a Lua script as a string from the entity.
```APIDOC
## getLuaScript
### Description
Get a Lua script as a string from the entity.
### Response
#### Success Response (200)
- **return** (string) - The Lua script as a string.
```
--------------------------------
### Set Custom Background by URL
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/backgrounds.md
Replaces the current background with a custom background loaded from the provided URL. Returns a boolean indicating success. No setup is required.
```lua
Backgrounds.setCustomURL("http://example.com/mybackground.jpg")
```
--------------------------------
### getVelocity
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the current linear velocity of the object.
```APIDOC
## getVelocity
### Description
Returns a Vector of the current velocity.
### Return
- **Vector** - The current velocity of the object.
```
--------------------------------
### getPosition
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the current world position of the object.
```APIDOC
## getPosition
### Description
Returns a Vector of the current World Position.
### Return
- **Vector** - The current world position of the object.
```
--------------------------------
### getOptions()
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/behavior/layoutzone.md
Retrieves the current options of a layout zone.
```APIDOC
## getOptions()
### Description
Returns the layout zones options.
### Method
```
getOptions()
```
### Return
- [options](../types.md)
### Example
```lua
log(zone.LayoutZone.getOptions())
```
```
--------------------------------
### onCollisionEnter
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an Object starts colliding with the script-owner Object.
```APIDOC
## onCollisionEnter collision_info
### Description
Called when an Object starts colliding with the script-owner Object.
### Parameters
#### Path Parameters
- **collision_info** (Table) - Description not available
```
--------------------------------
### showOptionsDialog
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Shows a dropdown options dialog to the player.
```APIDOC
## showOptionsDialog
### Description
Shows the dropdown options dialog to the player, and executes `callback` if they click `OK`.
### Parameters
- **description** (string) - Required - The label for the options.
- **options** (Table) - Required - A table of options to display in the dropdown.
- **default_value** (int) - Optional - The index of the default selected option.
- **callback** (function) - Required - The function to execute with the selected option index if the user clicks OK.
### Returns
- **bool** - True if the dialog was shown successfully, false otherwise.
```
--------------------------------
### getBounds
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/object.md
Gets the global bounding box dimensions of the object.
```APIDOC
## getBounds
### Description
Returns a Vector describing the size of an object in Global terms.
### Return
- **Vector** - A vector representing the object's bounds.
```
--------------------------------
### Autoexec Script: Smart Chat Keybinding
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/systemconsole.md
Creates a smart chat keybinding that switches between team chat and game chat based on the player's current team.
```bash
store_text smart_chat
skip :teamchat team
chat_tab_game
skip :activate
:teamchat
chat_tab_team
:activate
chat_input
end smart_chat
bind y @exec -v smart_chat
```
--------------------------------
### Get Gravity Direction
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/physics.md
Retrieves the current direction of gravity.
```Lua
Physics.getGravity()
```
--------------------------------
### Get Current Background
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/backgrounds.md
Retrieves the name of the current background.
```APIDOC
## getBackground()
### Description
Returns the current background name.
### Method
GET (conceptual)
### Endpoint
Backgrounds.getBackground()
### Return
- **name** (string) - The name of the current background.
```
--------------------------------
### setUITheme(theme)
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Sets the UI theme for the player.
```APIDOC
## setUITheme(theme)
### Description
Sets the UI theme for the player.
### Parameters
#### Path Parameters
- **theme** (string) - Required - A string representing a theme.
### Tip
You can view the expected theme format by in-game going to Menu -> Configuration -> Interface -> Theme. Select a
theme then press "Import/Export".
### Request Example
```lua
Player.white.setUITheme("button_normal #FFC0C0")
```
```
--------------------------------
### onObjectCollisionEnter
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/events.md
Called when an Object starts colliding with a collision registered Object.
```APIDOC
## onObjectCollisionEnter
### Description
Called when an Object starts colliding with a collision registered Object.
### Parameters
#### Path Parameters
- **registered_object** (Object) - Required - The object that has collision registration enabled.
- **collision_info** (Table) - Required - Information about the collision.
### Request Example
```lua
function onObjectCollisionEnter(registered_object, collision_info)
print("Collision entered with: " .. registered_object.name)
end
```
### Response
This function does not return a value.
```
--------------------------------
### setUITheme
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/player/instance.md
Sets the UI theme for the player.
```APIDOC
## setUITheme
### Description
Sets the UI theme for the player.
### Parameters
- **theme** (string) - Required - The name of the UI theme to apply.
### Returns
- **bool** - True if the operation was successful, false otherwise.
```
--------------------------------
### Lua Boolean Type Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents a true or false value.
```lua
true
```
--------------------------------
### Lua Float Type Example
Source: https://github.com/berserk-games/tabletop-simulator-api/blob/master/docs/types.md
Represents a non-decimal or floating-point number.
```lua
2.032
```