segunda-feira, 6 de março de 2017

BP Compendium 3: Clamp

Clamp


It receives an input value and the minimum and maximum values. If the input value is between minimum and maximum, it is returned without modification. If it is below the minimum, the minimum value is returned. If it is above the maximum, the maximum value is returned.

Input

  • Value: Input value that will be compared with the "Min" and "Max". 
  • Min: The lowest value that can be returned. 
  • Max: The highest value that can be returned.

Output

  • Return Value: Value between "Min" and "Max".


Example Usage: 

In this example there is a variable called "Health". The value of this variable must be between 0 and 100. A function was created that should be used to modifier the value of the "Health" variable. This function has the parameter "Amount". The value of "Amount" can be negative indicating damage or can be positive when the player picks up a health pack. The "Clamp" is used to ensure that the "Health" variable is between 0 and 100.

Click to enlarge


In another example there is an event that calculates the power attack of a character. This power attack is based on the sum of the variables "Base Attack" and "Attack Modifier". The variable "Attack Modifier" can indicate attack bonuses or it can have negative value indicating some bad state of the character. But no matter how bad the character's attack penalties are, the minimum power attack is 500. Similarly, the maximum value of the power attack is 2000, even if the sum of the base attack with the attack bonus was higher.

Click to enlarge


Table of Contents