Variables, functions and data types
World logic rules remember and calculate values with variables. Use them for values such as a score, remaining attempts or a quest stage. A function is a group of actions shared by several rules. Enums and data types group values into a fixed shape.
| Feature | What it does | type used |
|---|---|---|
| Variables | Remember values. | Action Set variable (set_var) · condition Compare (compare) · expression {name} |
| Function | A rule that runs only when another action calls it. | Trigger Function (function) · 5 calling actions |
| Enum | A type that holds only one of a fixed set of values. | Type of a variable or data type field |
| Data type | A type made of several fields (similar to a class). | Type of a variable |
How to open
Section titled “How to open”| What | Where |
|---|---|
| Variables, enums and data types window | Variables button at the top left of the World logic panel |
| Set variable · Compare · Function types | Add action · Add condition in the World logic panel · the Variables · functions group in the trigger type menu, or the Add node window in the Logic graph |
Quick start
Section titled “Quick start”Count a score per player and show a title when it reaches 10.
- Click Variables in the World logic panel.
- On the Variables tab, click Add variable.
- Set the name to
score, typeint, scope Player, initial value0. - Click Apply (one Ctrl+Z step).
- Add a Set variable action to the rule that awards points. Set variable
score, operationadd, value1. - Add a Branch (if) action to the same rule. Set left
{score}, comparison>=, right10. - In the Logic graph, drop the yellow pin of the If true row on an empty spot. A new Function rule (
func_1) is created. - Add a Screen title action to that function rule.
Variables
Section titled “Variables”Declaration
Section titled “Declaration”Each row on the Variables tab is one variable.
| Field | Meaning |
|---|---|
| Name | Used as {name} in expressions. |
| Type | One of the basic types, an enum or a data type |
| Scope | Global (one value per scene) · Player (one value per player) |
| Initial value | If empty, the zero value of the type. |
| Type | Example value | Initial value (when empty) |
|---|---|---|
bool | true · false | false |
int | 3 | 0 |
float | 2.5 | 0 |
string | 안녕 | Empty text |
player | Player name | Empty text |
actor | Actor id | Empty text |
position | x y z (separated by spaces) | 0 0 0 |
| Enum | One value of that enum | First value |
| Data type | A value per field (below) | Initial value per field |
All values are stored as text. Numbers are written to three decimal places.
You can also use names that you have not declared. Such a name becomes a global text variable. It uses the same storage as the Flag condition and the Set flag action. Declare a variable when you need a type, player scope or an initial value.
Expressions
Section titled “Expressions”Write expressions in value fields (the value of Set variable, the left and right of Compare, etc.).
{name}is replaced with its value.- If the remaining text contains only numbers and
+-*/%(), it is calculated (for example{score} * 2 + 1). - Otherwise the replaced text is used as-is (for example
{player} 님 환영).
- Division by 0 gives 0.
- Unknown names become empty text.
Names are looked up in this order: local variables (function arguments · {index}) → per-player variables → global variables → special names.
| Special name | Value |
|---|---|
{player} | Name of the player who triggered it |
{player_x} · {player_y} · {player_z} | Position of the player who triggered it |
{player_pos} | Position of the player who triggered it as x y z |
{time} | Seconds since the scene started |
{random} | A random number between 0 and 1 |
{index} | Current number inside Repeat (0, 1, 2 …) |
Set variable
Section titled “Set variable”Fields of the Set variable action (set_var).
| Field | Value | Meaning |
|---|---|---|
| Variables | Name | For a data type variable, include the field, as in hero.hp. |
| Scope | auto · global · player · local | auto = as declared. If undeclared, local when a local variable of the same name exists, otherwise global. local = only within this execution |
| Calculate | Table below | |
| Values | Expression |
| Operation | Meaning |
|---|---|
set | Replaces with the value. |
add · sub · mul · div · mod | Add · subtract · multiply · divide · remainder. Division by 0 gives 0. |
min · max | The smaller or larger of the current value and the value |
append | Appends text to the end. |
toggle | Flips true ↔ false (the value is not used). |
If the current value is not a number, it is treated as 0 in numeric operations.
Compare
Section titled “Compare”The Compare condition (compare) and the Branch (if) action compare using the left, comparison and right fields.
| Comparison | Meaning |
|---|---|
== · != | Compares as numbers if both are numbers, otherwise as text (case-sensitive). |
< · <= · > · >= | Compares numbers only. False if not numbers. |
contains | The left text contains the right text |
starts_with | The left text starts with the right text |
Functions
Section titled “Functions”A function is a rule whose trigger is Function. It does not fire on its own. It runs only when a calling action calls it by name.
| Function trigger field | Meaning |
|---|---|
| Function name | The name used to call it. |
| Parameter names | Names separated by commas (for example amount, target). The value passed on call becomes the local variable {amount}. |
- A function inherits the triggering player of the caller.
- If the function rule’s conditions are false, only that function is skipped.
- Filters (once · cooldown · permission) are not used in function rules.
Calling actions
Section titled “Calling actions”| Action | type | Fields | What it does |
|---|---|---|---|
| Call function | call | Function · Arguments (name=expression, …) | Runs the function, then the next action when it finishes |
| In order (sequence) | sequence | Functions (commas) | Several functions in turn. The next function starts after the previous one finishes |
| Branch (if) | branch | Left · comparison · Right · If true · If false | Compares and calls one function. Does nothing if that side is empty |
| Repeat | repeat | Count (1–100) · Function | Runs the function the given number of times in turn. {index} = 0, 1, 2 … |
| For each player | for_each_player | Recipients · Function | For each recipient, runs the function in turn with that player as the triggering player |
- When a called function reaches Wait, the caller waits too. It goes to the next action only after the function finishes.
- Functions can call functions up to a depth of 16. Beyond that, the call is cut off and an error is logged (recursion loop).
- Argument expressions are evaluated at call time.
Since 0.9.11: Write only one function per call field. Writing several functions is a check error. To call them in turn, use In order (sequence). Two or more function rules with the same name are also a check error.
Functions vs signals
Section titled “Functions vs signals”| Function | Signal | |
|---|---|---|
| Calling action | Call function · In order · Branch · Repeat · For each player | Send signal |
| Receiver | The one Function rule with that name | All On signal rules with that name (broadcast) |
| Waiting | Waits until the function finishes (including wait) | Does not wait |
| Graph | Yellow function pin — one wire per pin | Signal pin — wires to all receiving rules |
Since 0.9.11: The Variables window now has three tabs (variables · enums · data types).
On the Enum tab, click Add enum.
| Field | Example |
|---|---|
| Name | Job |
| Values (comma-separated) | warrior, mage, archer |
- You can pick it as the type of a variable or data type field.
- The initial value of a variable of that type is the set initial value, or the first value if none.
- An initial value or a Set variable value outside the enum produces a check warning.
Data types
Section titled “Data types”On the Data types tab, click Add data type, then add fields with Add field.
| Field | Example |
|---|---|
| Data type name | Hero |
| Field name · Field type · Initial value | hp · int · 20 / job · Job / gold · int |
A field type is a basic type, an enum or another data type.
A data type variable expands into a value per field. Use the variable hero (type Hero) as follows.
| Where | Example |
|---|---|
| Expression | {hero.hp} · {hero.job} |
| Set variable variable field | hero.hp |
| Compare left | {hero.job} |
| Nested data type | {hero.stats.str} |
- The scope follows the variable declaration.
- Using Set variable on
heroas a whole is a check error. Pick a field. - The initial values of a data type variable are set per field (on the data types tab). The initial value in the variable row is not used.
Checks
Section titled “Checks”When you click Apply, the editor checks and shows problems as notifications.
| Kind | Contents |
|---|---|
| Error | Naming rules (start with a letter; letters, digits and _) · name clashes (among basic types, enums and data types) · enum without values · data type without fields · missing type · data type that contains itself (loop) · Set variable on a whole data type · duplicate variable declarations |
| Warning | Initial value outside the enum · Set variable value outside the enum · initial value in a data type variable row |
Checks on the function side are as follows.
| Kind | Contents |
|---|---|
| Error | Missing function name · function rules with the same name · several functions in one call field |
| Warning | Function with no calling action · filters enabled on a function rule |
Options
Section titled “Options”Buttons in the World logic variables · enums · data types window.
| Button | What it does |
|---|---|
| Add variable · Add enum · Add data type | Adds a new row. |
| Add field | Adds a field to a data type. |
| Remove (trash can) | Removes that row or field. |
| Apply | Saves all three tabs at once. One undo step. |
| Close | Closes without saving. |
Shortcuts
Section titled “Shortcuts”| Key | Action |
|---|---|
| Esc | Close the window (unapplied changes are discarded) |
| Ctrl+Z | Undo Apply |
Tips / notes
Section titled “Tips / notes”- Nothing is saved until you click Apply.
- During Play, you can see variable values in the world logic log of Play (rows of the form “variable name = value”).
- The server plugin must also run variables and functions by the same rules. Check the server plugin version for server-side support.
- On the server, data type variables are stored under their expanded names (
hero.hp, etc.).