Skip to content
NP Editor Docs

Variables, functions and data types

World logic rules remember and calculate values (score · remaining tries · quest stage …) with variables. A function is a rule that runs only when another action calls it, and enums and data types bundle values into a fixed shape.

FeatureActionNodes that use it
VariableRemembers a valueSet variable · the “Compare” condition · {name} inside fields
FunctionA rule that runs only when calledThe Function event · Call function · Flip Flop · Switch …
enumA type that holds one of a fixed set of valuesThe type of a variable or data type field
Data typeA type made of several fields (similar to a class)The type of a variable, {hero.hp}

Click Variables at the top left of the World logic tab to open the “World logic variables · enums · data types” window.

  1. On the Variables tab, click Add variable twice and fill in the two rows: score · int · Global · 0, and coins · int · Player · 0 (name · type · scope · initial value).

    The two rows score and coins on the Variables tab

  2. On the “enum” tab, click Add enum and type the name Job and the values warrior, mage, archer (initial value = the first value).

    Job on the enum tab

  3. On the Data types tab, click Add data type and type the name Hero. Change the first field to hp · int · 20, create a second field job with Add field, and select Job (enum) as its type.

    Hero on the Data types tab — hp and job

  4. Click Apply. All three tabs are saved at once (one Ctrl+Z step). Press Esc to close the window.

    The Apply button

  1. In the Logic graph, connect Timer (global) (interval 1 second) → Set variable (variable score · calculation add · value 1) → Set variable (coins · add · 1) → Call function with exec pins. Drop the yellow pin of Call function on an empty spot to create a new function rule func_1. Add Action bar text (text Score: {score}) to that function.

    Timer → two Set variable nodes → Call function → Action bar text inside the function

  2. Click the ▶ (Play) button. Every second score goes up by 1, and the function shows “Score: 1” · “Score: 2” … on the action bar. The “Flags:” line of the Play info overlay shows the current values. Press Esc to stop.

    The action bar showing Score: 2 and the flags line in Play

  • If you set a Player scope variable in a rule with no triggering player, such as Timer (global), the value goes into the global value (coins=2 in the step 6 screenshot). To count per player, use an event that a player triggers (When a player joins · On zone enter …) or “Run for = For each player” in “Every tick (server tick)”.
  • In text with nothing to calculate (Welcome, {player}), only the {name} parts are replaced with their values. If there are numbers and operators, it is calculated as an expression ({score} * 2 + 1).
  • The arguments of the trigger When a command is typed become {name} variables with exactly those names, and in the logic graph they appear as typed value pins (word · text · choice = text, int = integer, number = decimal, bool = true/false, player = player). If you give an argument the same name as a declared variable, {name} becomes the variable’s value instead of what was typed, so the check reports an error — World logic.
  • For the initial value of a block variable and the value of Set variable, use the custom block np:<id>. On export it becomes that block’s note block state and goes to the server (the editor original stays np:<id>) — World logic.
FieldMeaning
NameWritten as {name} in expressions (starts with a letter; letters, digits and _).
Typebool · int · float · string · player · actor · position · block · item · sound · particle · effect · enum · data type
ScopeGlobal (one value per scene) · Player (one value per player)
Initial valueIf empty, the zero value of the type. For the block type, minecraft:stone or np:<id> (a custom block)

Value fields take expressions.

What you can useExample
Variables · fields · axes{score} · {hero.hp} · {spot}.y
Valuesnumber 2.5 · vector "1 64 -3" · text 'mage' · true false
Operatorsor · and · not · == != < <= > >= · + - * / % · ^
Math functionssin cos … min max clamp lerp mod · random … · dist len … · 0.10.2: inverse_lerp wrap snap
  • Examples: {score} * 2 + 1 (score = 4 → 9) · mod(-7, 3) = 2 (sign of the divisor) · clamp(15, 0, 10) = 10 · {spot}.y (spot = 1 64 -3) = 64.
Special nameValue
{player}Name of the triggering player
{player_x} · {player_y} · {player_z} · {player_pos}Position of the triggering player
{time}Seconds since the scene started
{random}A random number between 0 and 1
{index}The current count inside a repeat or loop
{message}(chat trigger) The chat text
{command} · {args} · argument names(command trigger) The command name typed · the argument text · the value typed for each argument
FieldValue
VariablesName (for a data type, down to the field, like hero.hp)
Scopeauto (as declared) · global · player · local
Calculateset · add · sub · mul · div · mod · min · max · append · toggle
ValuesExpression
NodetypeAction
Call functioncallRuns the function, then the next action when it ends
In order (sequence)sequenceSeveral functions in order
Branch · Ifbranch · ifCalls one function by a comparison or expression
Repeat · Loop · For eachrepeat · while · for_eachRepeats the body function ({index})
For each playerfor_each_playerMakes each recipient the triggering player in turn
Switch · Flip Flopswitch · flip_flop0.10.2 — Logic graph
  • A function inherits the caller’s triggering player and local values (node results). When the called function reaches “Wait”, the caller waits too.
  • When you use the flow nodes Gate (pass condition), Return (stop here) or Do Once inside a function, only that function ends and the caller goes on to its next action.
ButtonAction
Add variable · Add enum · Add data type · Add fieldNew row · new field
ApplySaves all three tabs at once (one undo step)
Close (Esc)Closes without saving