Logic Programming
This article covers the boilerplate schema and functions that come with custom logic blocks as part of the unbound API (Lua). If you you're new to unbound and haven't read the Custom Logic Blocks article, you might find it helpful to review that first.
Unbound Schema
A schema is a Lua table that defines the input and output (I/O) for a logic block.
- Each entry can be either an input or an output.
- A variable name and type is required
- Some input types allow optional parameters to control that input's UI
- All entries can define an info parameter as a plain-text description of what that I/O does
- The schema itself can also define tags and a color for controlling how the block will be categorized and displayed in the Logic Library.
Here is the full list of accepted I/O as of this writing.
schema = {
{info = "describe the logic block, displays on hover in the librar"}
{color = vec4(252.0 / 255.0, 186.0 / 255.0, 3.0 / 255.0, 1.0)},
{tags = {"builtins", "model"}},
{input/output = "myEntity", type = "entity"}, — connect any entity to your block
{input/output = "myNumber", type = "number", min = 0.0, max = 10.0, default = 5.0}, — input numeric values with a slider
{input/output = "myNumber", type = "number", gui = “text“, default = 1.0}, — input numeric values with a text field
{input/output = "myStateValue", type = "boolean"}, — input a true/false boolean state with a button
{input/output = "myName", type = "string"}, — input a string in a text field
{input/output = "my2DPosition", type = "vec2"}, — connect a 2D vector
{input/output = "my3DPosition", type = "vec3"}, — connect a 3D vector
{input/output = "my4DVec", type = "vec4"}, — connect a 4D vector
{input/output = "myColor", type = "vec4", gui = “color“}, — pick a color
{input/output = "myRotation", type = "quat"}, — connect a rotation
}
Info
The info property defines what will display when the mouse hovers over a logic block in the logic library.
Color and Tags
The color and tag lines allow you to define the color of the logic block (as a vec4) and the tags by which this block can be filtered. For example, if you've remixed a logic block or have created your own you may want to store them under a myLogic tag but also keep a tag like logic so it shows when filtered by the same tag as the block that it was remixed from (in this case the timer block)
We'll make it an obnoxious red so it stands out.
Once we save and return to the logic library we can drag in our newly tagged and colored block.
Data Types
The accepted data types for unbound I/O includes:
- entity: numeric value
- boolean: true or false (state, on/off)
- string: text
- vec2: 2D vector connection
- vec3: 3D vector connection
- vec4: 4D vector connection
- color: color picker
- quat: rotation connection
Numbers by default will display as a slider. But you can control the range of the slider with the min and max attributes or you can force it to display as a text field by setting the gui attribute to text. This will display a text field with steppers.
All number fields allow you to define a default value. This is the value the block will use for calculations unless it receives an new value from a connected input.
Bools display as a toggle button (on or off), colors present a color picker, strings create an editable text field, and the rest only offer connection dots to matching I/O.
Built in Functions
These are the main entry points to operate logic, start() is invoked when the game starts, update() is invoked once per frame.
Within these two functions, you are allowed to use any of the unbound APIs as described in the unbound API.
Lua Programming Guide
For a full guide to the Lua programming language, visit lua.org