Appearance
Action Math Variable
Applies a mathematical operation to a variable and stores the result.
Inputs: 1 · Outputs: Then
Settings
| Setting | Type | Required | Default | Description |
|---|---|---|---|---|
| Variable Name | String | Yes | — | The variable the result will be saved to. |
| Use Variable as First Operand | Boolean | Yes | true | When enabled, the variable itself is the left-hand side of the operation. |
| First Value | Number | Yes (if disabled) | — | Left-hand value of the operation. |
| Operation | Select | Yes | Addition [+] | Mathematical operation to perform. |
| Second Value | String/Num | Yes (for some) | — | Right-hand value for arithmetic operations such as addition, subtraction, multiplication, division, remainder, and power. |
| Second Value | String/Num | Yes (for min/max/random) | — | Upper or lower boundary for minimum, maximum, and random operations. |
| Log Base | Select | Yes (if logarithm) | Common Log - lg (base 10) | Base of the logarithm. |
| Custom Log Base | Number | Yes (if custom log base) | — | Base value when Log Base is set to Custom. |
| Angle Unit | Select | Yes (if trigonometry) | Degrees (°) | Unit used for sine, cosine, and tangent operations. |
| Decimal Places | Slider | No (if rounding) | 0 | Number of decimal places to keep when rounding. |
| Format Output | Boolean | No | false | Removes trailing decimal zeros when possible. |
TIP
Math Variable features Smart Scope Autodetection. If the target variable name is already declared in a scope (Local, Player, or Global), the math operation will automatically execute and save back to that scope. If the variable name does not exist anywhere yet, it defaults to Player scope if a triggering player is present, or Global scope otherwise. For a detailed breakdown, see the Variable Scopes Guide.
Operations
| Operation | Notes |
|---|---|
| Addition [+] | Adds the second value to the first. |
| Subtraction [-] | Subtracts the second value from the first. |
| Multiplication [x] | Multiplies the first value by the second. |
| Division [÷] | Divides the first value by the second. |
| Remainder [%] | Returns the remainder after division. |
| Increment [+1] | Increases the first value by exactly 1. |
| Decrement [-1] | Decreases the first value by exactly 1. |
| Negate (Flip +/-) | Flips the sign of the value. |
| Absolute Value - abs(x) | Returns the distance from zero. |
| Floor - ⌊x⌋ | Rounds down to the nearest whole number. |
| Ceiling - ⌈x⌉ | Rounds up to the nearest whole number. |
| Round - ≈x | Rounds to the nearest whole number. 1-4 rounds down, 5-9 rounds up |
| Square Root - √x | Calculates the square root. |
| Power - x^n | Raises the first value to the second value. |
| Logarithm - log(x) | Calculates the logarithm using the selected base. |
| Sine - sin(x) | Applies the sine function. |
| Arcsine - asin(x) | Applies the inverse sine function. |
| Cosine - cos(x) | Applies the cosine function. |
| Arccosine - acos(x) | Applies the inverse cosine function. |
| Tangent - tan(x) | Applies the tangent function. |
| Arctangent - atan(x) | Applies the inverse tangent function. |
| Minimum - min(a,b) | Returns the lower of two values. |
| Maximum - max(a,b) | Returns the higher of two values. |
| Random - rand(a,b) | Generates a random number between two values. |
Examples
Example 1: Incrementing a Kill Counter
- Set Variable Name to
kills. - Enable Use Variable as First Operand (This ensures we add to the existing count).
- Set Operation to
Increment [+1]. Result: Every time this node runs, thekillsvariable goes up by 1.
Example 2: Preventing Negative Health When Taking Damage
Subtract damage from the player’s health, then clamp it so it never goes below 0.
Create a Math Variable
- Variable Name:
player_health - Enable Use Variable as First Operand
- Operation:
Subtraction [-] - Second Value:
%damage%
- Variable Name:
Add another Math Variable right after
- Variable Name:
player_health - Enable Use Variable as First Operand
- Operation:
Maximum - Second Value:
0
- Variable Name:
Apply it with a Set Health node using
player_health
What this does: Damage gets subtracted first. If the result drops below 0, the Maximum operation forces it back up to 0, so health never becomes negative.
Example 3: Generating a Random Gold Drop
- Set Variable Name to
gold_found. - Disable Use Variable as First Operand (We want to generate a fresh number, not base it on previous gold).
- Set First Value to
10(The minimum gold drop). - Set Operation to
Random [rand(a,b)]. - Set Second Value to
50(The maximum gold drop). - Set Decimal Places to
0(So you don't drop fractions of a coin). Result: Thegold_foundvariable will be assigned a random whole number between 10 and 50. - Connect the output to a Give Item node that gives the player gold nuggets based on
%gold_found%.
