Appearance
Action Math Variable
The Math Variable node performs a mathematical operation and stores the final result inside a specified variable. This node can be used for simple arithmetic (like adding to a score), complex calculations (like calculating logarithmic decay), or utility functions (like generating random numbers or clamping values).
If the target variable does not currently exist, this node will create it. If it already exists, the node will overwrite its value with the new calculation.
Inputs: 1 · Outputs: Then
Settings
| Setting | Type | Required | Default | Description |
|---|---|---|---|---|
| Variable Name | String | Yes | — | The target variable where the final calculated result will be stored. If "Use Variable as First Operand" is enabled, this variable's current value is also used as the starting point (left-hand side) of the equation. |
| Use Variable as First Operand | Boolean | Yes | true | Determines the left-hand side of the equation. Enabled: Modifies the existing variable ( x = x + 5).Disabled: Ignores the current variable value and uses a custom starting number ( x = 10 + 5). |
| First Value | Number | Yes (if custom) | — | The left-hand value of the equation. This field only appears if "Use Variable as First Operand" is toggled off. |
| Operation | Select | Yes | Addition [+] | The specific mathematical formula or logic to apply to your numbers. |
| Second Value | String/Num | Yes (for some) | — | The right-hand operand used to modify the first value. Required for operations that need two numbers (Addition, Subtraction, Multiplication, Division, Remainder, Power). |
| Second Value (Min/Max/Rand) | String/Num | Yes | — | Acts as the upper or lower boundary when comparing numbers or generating a random range. |
| Log Base | Select | Yes (for logarithims) | Common (10) | Selects the base for logarithmic calculations. Options include Natural (Base e), Common (Base 10), Binary (Base 2), or a Custom base. |
| Custom Log Base | Number | Yes (if custom log base) | — | Defines the mathematical base when the Log Base is set to "Custom". |
| Angle Unit | Select | Yes (if trigonometry) | Degrees | Determines how input numbers are interpreted for Sine, Cosine, and Tangent operations. |
| Decimal Places | Number | No (if rounding) | 0 | Defines how many numbers after the decimal point are kept when using the Round operation (0–10). A value of 0 rounds to the nearest whole number. |
Available Operations
| Operation | Symbol | Requires Second Value | Description & Behavior | Example |
|---|---|---|---|---|
| Addition | + | Yes | Adds the second value to the first. | 10 + 5 = 15 |
| Subtraction | - | Yes | Subtracts the second value from the first. | 10 - 5 = 5 |
| Multiplication | × | Yes | Multiplies the first value by the second. | 10 × 5 = 50 |
| Division | ÷ | Yes | Divides the first value by the second. Don't divide by 0 :b | 10 ÷ 5 = 2 |
| Remainder | % | Yes | Performs a modulo operation, returning the remainder after division. Excellent for checking if a number is even/odd. Works by dividing the first value by the second, the remainder is what is left over. | 10 % 3 = 1 since 9 / 3 = 3 with a remainder of 1 |
| Increment | +1 | No | Increases the first value by exactly 1. Commonly used for loops and counters. | 10 + 1 = 11 |
| Decrement | -1 | No | Decreases the first value by exactly 1. | 10 - 1 = 9 |
| Negate | ± | No | Flips the sign of the value. Positives become negative; negatives become positive. | 10 → -10 |
| Absolute Value | |x| | No | Returns the distance from zero, converting any negative number into a positive one. | |-15| = 15 |
| Floor | ⌊x⌋ | No | Rounds a decimal number down to the nearest whole number. | 4.9 → 4 |
| Ceiling | ⌈x⌉ | No | Rounds a decimal number up to the nearest whole number. | 4.1 → 5 |
| Round | ≈x | No | Rounds to the closest whole number. x.5 rounds up. | 4.5 → 5 |
| Square Root | √x | No | Calculates the square root of the first value. | √16 = 4 |
| Power | x^n | Yes | Raises the first value (base) to the power of the second value (exponent). | 2^3 = 8 |
| Logarithm | log(x) | No | Calculates the logarithm of the value based on the selected Log Base. | log10(100) = 2 |
| Sine | sin(x) | No | Applies the sine function to the value. Interprets input using the selected Angle Unit (Degrees or Radians). | sin(90°) = 1 |
| Cosine | cos(x) | No | Applies the cosine function to the value. Interprets input using the selected Angle Unit (Degrees or Radians). | cos(0°) = 1 |
| Tangent | tan(x) | No | Applies the tangent function to the value. Interprets input using the selected Angle Unit (Degrees or Radians). Note: tangent is undefined for angles where cosine = 0 (e.g., 90° in Degrees). | tan(45°) = 1 |
| Minimum | min(a,b) | Yes | Compares the two values and outputs the lowest one. Useful for preventing a variable from exceeding a maximum limit. | min(100, 50) = 50 |
| Maximum | max(a,b) | Yes | Compares the two values and outputs the highest one. Useful for preventing a variable from dropping below zero. | max(-5, 0) = 0 |
| Random | rand(a,b) | Yes | Generates a random number between the first value and the second value. | rand(1, 10) = 7 |
Examples
Example 1: Incrementing a Kill Counter
Ideal for keeping track of simple stats over time.
- 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: Taking Damage (Preventing Negative Health)
How to subtract health, but ensure the player's health never drops below 0.
- Set Variable Name to
player_health. - Enable Use Variable as First Operand.
- Set Operation to
Subtraction [-]. - Set Second Value to
25(simulating 25 damage). - Add a second Math Variable node right after. Set Variable Name to
player_health, toggle First Operand ON, set Operation toMaximum, and set Second Value to0. Result: Health goes down by 25. If health drops to -10, theMaximumoperation sees-10and0, and chooses0, preventing negative health. - Add a Set Health node after to apply the
player_healthvariable to the actual player health.
Example 3: Generating a Random Gold Drop
Ideal for loot generation or dice rolls.
- 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. - Add a Random Chance node and set the chance to
%gold_found% - Connect the Success output to a Give Item node that gives the player gold nuggets based on
%gold_found%. Connect Failure to a message that says "No gold found this time!"
