Skip to content

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

SettingTypeRequiredDefaultDescription
Variable NameStringYesThe 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 OperandBooleanYestrueDetermines 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 ValueNumberYes (if custom)The left-hand value of the equation. This field only appears if "Use Variable as First Operand" is toggled off.
OperationSelectYesAddition [+]The specific mathematical formula or logic to apply to your numbers.
Second ValueString/NumYes (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/NumYesActs as the upper or lower boundary when comparing numbers or generating a random range.
Log BaseSelectYes (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 BaseNumberYes (if custom log base)Defines the mathematical base when the Log Base is set to "Custom".
Angle UnitSelectYes (if trigonometry)DegreesDetermines how input numbers are interpreted for Sine, Cosine, and Tangent operations.
Decimal PlacesNumberNo (if rounding)0Defines 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

OperationSymbolRequires Second ValueDescription & BehaviorExample
Addition+YesAdds the second value to the first.10 + 5 = 15
Subtraction-YesSubtracts the second value from the first.10 - 5 = 5
Multiplication×YesMultiplies the first value by the second.10 × 5 = 50
Division÷YesDivides the first value by the second. Don't divide by 0 :b10 ÷ 5 = 2
Remainder%YesPerforms 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+1NoIncreases the first value by exactly 1. Commonly used for loops and counters.10 + 1 = 11
Decrement-1NoDecreases the first value by exactly 1.10 - 1 = 9
Negate±NoFlips the sign of the value. Positives become negative; negatives become positive.10-10
Absolute Value|x|NoReturns the distance from zero, converting any negative number into a positive one.|-15| = 15
Floor⌊x⌋NoRounds a decimal number down to the nearest whole number.4.94
Ceiling⌈x⌉NoRounds a decimal number up to the nearest whole number.4.15
Round≈xNoRounds to the closest whole number. x.5 rounds up.4.55
Square Root√xNoCalculates the square root of the first value.√16 = 4
Powerx^nYesRaises the first value (base) to the power of the second value (exponent).2^3 = 8
Logarithmlog(x)NoCalculates the logarithm of the value based on the selected Log Base.log10(100) = 2
Sinesin(x)NoApplies the sine function to the value. Interprets input using the selected Angle Unit (Degrees or Radians).sin(90°) = 1
Cosinecos(x)NoApplies the cosine function to the value. Interprets input using the selected Angle Unit (Degrees or Radians).cos(0°) = 1
Tangenttan(x)NoApplies 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
Minimummin(a,b)YesCompares the two values and outputs the lowest one. Useful for preventing a variable from exceeding a maximum limit.min(100, 50) = 50
Maximummax(a,b)YesCompares the two values and outputs the highest one. Useful for preventing a variable from dropping below zero.max(-5, 0) = 0
Randomrand(a,b)YesGenerates 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.

  1. Set Variable Name to kills.
  2. Enable Use Variable as First Operand (This ensures we add to the existing count).
  3. Set Operation to Increment [+1]. Result: Every time this node runs, the kills variable 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.

  1. Set Variable Name to player_health.
  2. Enable Use Variable as First Operand.
  3. Set Operation to Subtraction [-].
  4. Set Second Value to 25 (simulating 25 damage).
  5. Add a second Math Variable node right after. Set Variable Name to player_health, toggle First Operand ON, set Operation to Maximum, and set Second Value to 0. Result: Health goes down by 25. If health drops to -10, the Maximum operation sees -10 and 0, and chooses 0, preventing negative health.
  6. Add a Set Health node after to apply the player_health variable to the actual player health.

Example 3: Generating a Random Gold Drop

Ideal for loot generation or dice rolls.

  1. Set Variable Name to gold_found.
  2. Disable Use Variable as First Operand (We want to generate a fresh number, not base it on previous gold).
  3. Set First Value to 10 (The minimum gold drop).
  4. Set Operation to Random [rand(a,b)].
  5. Set Second Value to 50 (The maximum gold drop).
  6. Set Decimal Places to 0 (So you don't drop fractions of a coin). Result: The gold_found variable will be assigned a random whole number between 10 and 50.
  7. Add a Random Chance node and set the chance to %gold_found%
  8. 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!"

Oasis Admin Editor Documentation