Skip to content

Action Math Variable

Applies a mathematical operation to a variable and stores the result.

Inputs: 1 · Outputs: Then

Settings

SettingTypeRequiredDefaultDescription
Variable NameStringYesThe variable the result will be saved to.
Use Variable as First OperandBooleanYestrueWhen enabled, the variable itself is the left-hand side of the operation.
First ValueNumberYes (if disabled)Left-hand value of the operation.
OperationSelectYesAddition [+]Mathematical operation to perform.
Second ValueString/NumYes (for some)Right-hand value for arithmetic operations such as addition, subtraction, multiplication, division, remainder, and power.
Second ValueString/NumYes (for min/max/random)Upper or lower boundary for minimum, maximum, and random operations.
Log BaseSelectYes (if logarithm)Common Log - lg (base 10)Base of the logarithm.
Custom Log BaseNumberYes (if custom log base)Base value when Log Base is set to Custom.
Angle UnitSelectYes (if trigonometry)Degrees (°)Unit used for sine, cosine, and tangent operations.
Decimal PlacesSliderNo (if rounding)0Number of decimal places to keep when rounding.
Format OutputBooleanNofalseRemoves 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

OperationNotes
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 - ≈xRounds to the nearest whole number. 1-4 rounds down, 5-9 rounds up
Square Root - √xCalculates the square root.
Power - x^nRaises 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

  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: Preventing Negative Health When Taking Damage

Subtract damage from the player’s health, then clamp it so it never goes below 0.

  1. Create a Math Variable

    • Variable Name: player_health
    • Enable Use Variable as First Operand
    • Operation: Subtraction [-]
    • Second Value: %damage%
  2. Add another Math Variable right after

    • Variable Name: player_health
    • Enable Use Variable as First Operand
    • Operation: Maximum
    • Second Value: 0
  3. 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

  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. Connect the output to a Give Item node that gives the player gold nuggets based on %gold_found%.

Oasis Admin Editor Documentation