Skip to content

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.

FeatureWhat it doestype used
VariablesRemember values.Action Set variable (set_var) · condition Compare (compare) · expression {name}
FunctionA rule that runs only when another action calls it.Trigger Function (function) · 5 calling actions
EnumA type that holds only one of a fixed set of values.Type of a variable or data type field
Data typeA type made of several fields (similar to a class).Type of a variable
WhatWhere
Variables, enums and data types windowVariables button at the top left of the World logic panel
Set variable · Compare · Function typesAdd 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

Count a score per player and show a title when it reaches 10.

  1. Click Variables in the World logic panel.
  2. On the Variables tab, click Add variable.
  3. Set the name to score, type int, scope Player, initial value 0.
  4. Click Apply (one Ctrl+Z step).
  5. Add a Set variable action to the rule that awards points. Set variable score, operation add, value 1.
  6. Add a Branch (if) action to the same rule. Set left {score}, comparison >=, right 10.
  7. 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.
  8. Add a Screen title action to that function rule.

Each row on the Variables tab is one variable.

FieldMeaning
NameUsed as {name} in expressions.
TypeOne of the basic types, an enum or a data type
ScopeGlobal (one value per scene) · Player (one value per player)
Initial valueIf empty, the zero value of the type.
TypeExample valueInitial value (when empty)
booltrue · falsefalse
int30
float2.50
string안녕Empty text
playerPlayer nameEmpty text
actorActor idEmpty text
positionx y z (separated by spaces)0 0 0
EnumOne value of that enumFirst value
Data typeA 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.

Write expressions in value fields (the value of Set variable, the left and right of Compare, etc.).

  1. {name} is replaced with its value.
  2. If the remaining text contains only numbers and + - * / % ( ), it is calculated (for example {score} * 2 + 1).
  3. 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 nameValue
{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 …)

Fields of the Set variable action (set_var).

FieldValueMeaning
VariablesNameFor a data type variable, include the field, as in hero.hp.
Scopeauto · global · player · localauto = as declared. If undeclared, local when a local variable of the same name exists, otherwise global. local = only within this execution
CalculateTable below
ValuesExpression
OperationMeaning
setReplaces with the value.
add · sub · mul · div · modAdd · subtract · multiply · divide · remainder. Division by 0 gives 0.
min · maxThe smaller or larger of the current value and the value
appendAppends text to the end.
toggleFlips true ↔ false (the value is not used).

If the current value is not a number, it is treated as 0 in numeric operations.

The Compare condition (compare) and the Branch (if) action compare using the left, comparison and right fields.

ComparisonMeaning
== · !=Compares as numbers if both are numbers, otherwise as text (case-sensitive).
< · <= · > · >=Compares numbers only. False if not numbers.
containsThe left text contains the right text
starts_withThe left text starts with the right text

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 fieldMeaning
Function nameThe name used to call it.
Parameter namesNames 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.
ActiontypeFieldsWhat it does
Call functioncallFunction · Arguments (name=expression, …)Runs the function, then the next action when it finishes
In order (sequence)sequenceFunctions (commas)Several functions in turn. The next function starts after the previous one finishes
Branch (if)branchLeft · comparison · Right · If true · If falseCompares and calls one function. Does nothing if that side is empty
RepeatrepeatCount (1–100) · FunctionRuns the function the given number of times in turn. {index} = 0, 1, 2 …
For each playerfor_each_playerRecipients · FunctionFor 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.

FunctionSignal
Calling actionCall function · In order · Branch · Repeat · For each playerSend signal
ReceiverThe one Function rule with that nameAll On signal rules with that name (broadcast)
WaitingWaits until the function finishes (including wait)Does not wait
GraphYellow function pin — one wire per pinSignal 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.

FieldExample
NameJob
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.

On the Data types tab, click Add data type, then add fields with Add field.

FieldExample
Data type nameHero
Field name · Field type · Initial valuehp · 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.

WhereExample
Expression{hero.hp} · {hero.job}
Set variable variable fieldhero.hp
Compare left{hero.job}
Nested data type{hero.stats.str}
  • The scope follows the variable declaration.
  • Using Set variable on hero as 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.

When you click Apply, the editor checks and shows problems as notifications.

KindContents
ErrorNaming 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
WarningInitial 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.

KindContents
ErrorMissing function name · function rules with the same name · several functions in one call field
WarningFunction with no calling action · filters enabled on a function rule

Buttons in the World logic variables · enums · data types window.

ButtonWhat it does
Add variable · Add enum · Add data typeAdds a new row.
Add fieldAdds a field to a data type.
Remove (trash can)Removes that row or field.
ApplySaves all three tabs at once. One undo step.
CloseCloses without saving.
KeyAction
EscClose the window (unapplied changes are discarded)
Ctrl+ZUndo Apply
  • 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.).