Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

clamps

Status
Not open for further replies.

clark

Villager
Xy$
0.00
i want to use the .clamp on the gainExp function. can someone help me understand how to use .clamp(x,y) properly?
 

Xilefian

Adventurer
Xy$
0.00
JavaScript:
var newValue = Number( oldValue ).clamp( minimumValue, maximumValue );

// Example 1:
health += damage; // Change health (damage could be positive or negative)
health = Number( health ).clamp( 0, 100 ); // Clamp health between 0 and 100

// Example 2:
health = Number( health + damage ).clamp( 0, 100 ); // Do the above in 1 line
I'm pretty sure you can't have negative exp gained (correct me if I'm wrong, I'm presuming here), so clamp might be overkill for what you want to do. You probably only need to check if it's greater than the max value and clamp to that, rather than clamp to a minimum value as well;

JavaScript:
expGained = ( expGained > gainLimit ? gainLimit : expGained );
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm closing thread due to being addressed & solved if for any reason you would like it re-opened please report the post.
 
Status
Not open for further replies.
Top