Skip to main content

Subtraction

This node subtracts one number from another and returns the difference.

The Subtraction node performs mathematical subtraction with error handling and value validation.

The Subtraction node calculates the difference between two numbers (First Number - Second Number). It is a fundamental building block for arithmetic logic. It includes built-in validation to ensure inputs are valid numbers and that the result stays within acceptable bounds (-1,000,000,000,000 to 1,000,000,000,000).

Inputs

Numbers

DataDescription
First NumberThe number to subtract from (the minuend). Default: 0. Must be a valid number within the allowed range.
Second NumberThe number to subtract (the subtrahend). Default: 0. Must be a valid number within the allowed range.

Actions

SignalDescription
DoTriggers the subtraction calculation. The result is only updated when this signal is received.
ResetResets all inputs and the result to 0, and clears any errors.

Outputs

Data

DataDescription
ResultThe difference between the two numbers (First - Second).

Signals

SignalDescription
DoneTriggered when the calculation is successfully completed and the Result output has been updated.
Reset DoneTriggered when the Reset action is completed.

Usage

The Subtraction node is used for calculating differences, decrements, and negative offsets.

Example Use Cases

  1. Calculating Change: Determine remaining amount.
    • First Number: Total Payment
    • Second Number: Cost
    • Result: Change Due
  2. Health/Energy Bars: Decreasing player health.
    • First Number: Current Health
    • Second Number: Damage Taken
    • Result: New Health
  3. Coordinates: Calculating distance or offset between two points.
  4. Countdown: Decrementing a value by a specific step (though the Loop node is often better for this).

Detailed Behavior

  1. Input Validation:
    • Inputs are validated immediately upon setting.
    • Non-numeric values (NaN) cause an error.
    • Values outside the range of ±1,000,000,000,000 cause an error.
    • If an input error occurs, the node enters an error state and will not calculate until fixed.
  2. Calculation:
    • Triggered only by the Do signal.
    • Formula: First Number - Second Number.
    • If the result exceeds the ±1 trillion range, an error is logged, and the Done signal is not emitted.
  3. Error State:
    • Errors are logged to the console (e.g., "Input cannot exceed...").
    • The Reset signal clears the error state and resets values to 0.

Troubleshooting

  • No Output: If Do is triggered but Done does not fire, check the console. You likely have an invalid input or the result caused an underflow/overflow.
  • Wrong Direction: Remember that order matters: First Number minus Second Number. If you get a negative number when expecting positive, swap your inputs.