Minimum/Maximum range expression?

Get help using Construct 2

Post » Sun Dec 11, 2016 10:11 am

Is there a way of limiting an expression to having a maximum number? A bit like how you can use random(4,84) or something to pick any number between two numbers, no lower than, say, 4 and no higher than 84, can you limit the result to be no higher or lower via an expression?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Sun Dec 11, 2016 10:18 am

Do you mean something like clamp?

clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Sun Dec 11, 2016 11:15 am

Asmodean wrote:Do you mean something like clamp?

clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.


Ahh, clamp, yes that's the one, I knew there was one! I'm trying this:
Code: Select all
Pin offsetX: PlayerAnimations.Angle/40


and I want to limit it so it doesn't shift the X too far if the angle of the player is too extreme, clamp will work okay?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,268

Post » Sun Dec 11, 2016 12:58 pm

Zebbi wrote:Ahh, clamp, yes that's the one, I knew there was one! I'm trying this:
Code: Select all
Pin offsetX: PlayerAnimations.Angle/40


and I want to limit it so it doesn't shift the X too far if the angle of the player is too extreme, clamp will work okay?


Yeap, I think it should.
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Mon Dec 12, 2016 11:13 am

If you only want an upper bound, min(x, limit) will not return more than the limit, effectively acting as only enforcing the upper bound. Likewise max(x, limit) will act as a lower bound.
Scirra Founder
B
399
S
236
G
89
Posts: 24,543
Reputation: 195,430


Return to How do I....?

Who is online

Users browsing this forum: dop2000, t redeemed t and 23 guests