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
| Data | Description |
|---|---|
| First Number | The number to subtract from (the minuend). Default: 0. Must be a valid number within the allowed range. |
| Second Number | The number to subtract (the subtrahend). Default: 0. Must be a valid number within the allowed range. |
Actions
| Signal | Description |
|---|---|
| Do | Triggers the subtraction calculation. The result is only updated when this signal is received. |
| Reset | Resets all inputs and the result to 0, and clears any errors. |
Outputs
Data
| Data | Description |
|---|---|
| Result | The difference between the two numbers (First - Second). |
Signals
| Signal | Description |
|---|---|
| Done | Triggered when the calculation is successfully completed and the Result output has been updated. |
| Reset Done | Triggered when the Reset action is completed. |
Usage
The Subtraction node is used for calculating differences, decrements, and negative offsets.
Example Use Cases
- Calculating Change: Determine remaining amount.
First Number: Total PaymentSecond Number: CostResult: Change Due
- Health/Energy Bars: Decreasing player health.
First Number: Current HealthSecond Number: Damage TakenResult: New Health
- Coordinates: Calculating distance or offset between two points.
- Countdown: Decrementing a value by a specific step (though the Loop node is often better for this).
Detailed Behavior
- 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.
- Calculation:
- Triggered only by the
Dosignal. - Formula:
First Number - Second Number. - If the result exceeds the ±1 trillion range, an error is logged, and the
Donesignal is not emitted.
- Triggered only by the
- Error State:
- Errors are logged to the console (e.g., "Input cannot exceed...").
- The
Resetsignal clears the error state and resets values to 0.
Troubleshooting
- No Output: If
Dois triggered butDonedoes 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 NumberminusSecond Number. If you get a negative number when expecting positive, swap your inputs.