clamp - ryzom/ryzomcore GitHub Wiki


title: Clamp description: published: true date: 2023-03-12T12:45:57.684Z tags: editor: markdown dateCreated: 2023-03-12T11:21:02.502Z

clamp

The clamp native AI script function is used to restrict a value between two limits. The function returns the value clamped between the two limits provided.

The low bound is the minimum value of the two limits provided, while the upper bound is the maximum value. If the input value is out of the specified bounds, the function returns the nearest limit value.

Syntax

(clamped_value: f)clamp(value: f, lim1: f, lim2: f) // clamp_fff_f

Arguments

  • value (float): The value to clamp.
  • lim1 (float): The first clamp limit.
  • lim2 (float): The second clamp limit.

Return value

  • clamped_value (float): The value of value clamped between lim1 and lim2.

Example

(percentage)clamp(ratio, 0, 1)

This example code clamps the value of ratio between 0 and 1, and stores the result in the variable percentage.

⚠️ **GitHub.com Fallback** ⚠️