dfabulich / choicescript

ChoiceScript is a language for developing multiple-choice games.
http://www.choiceofgames.com/blog/choicescript-intro/
Other
410 stars 123 forks source link

Stat clamp function. #143

Closed danspinola closed 2 years ago

danspinola commented 2 years ago

A built-in function to clamp values between 0 and 100.

*comment assume variable dexterity, with value 95

*set dexterity stat(dexterity + 20)

*comment the return will be 100, despite the operation result being 115

Rationale

Stats are at the heart of ChoiceScript games and it is imperative to keep them inside the 0 to 100 range.

ChoiceScript offers built-in fairmath operations to deal with stats. However, fairmath comes with its own set of problems. For developers, it is harder to balance a game, for players stat changes can be unpredictable, especially near the extremes.

Linear operations may be desired except for the boilerplate needed to always keep stat variables inside the range.

The stat function offers a simple interface for those developers who prefer to use linear operations instead of the ones based on percentage points. The function clamps the value between the acceptable range.