Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Create clamp expression

Open Phill310 opened this issue 10 months ago • 11 comments

Description

Creates a clamp expression to clamp values between a min and a max. This is my first time working with skript so any help/tips would be appreciated :)


Target Minecraft Versions: any Requirements: none Related Issues: #6488

Phill310 avatar Apr 15 '24 06:04 Phill310

I think I'd rather fix the function return behaviour than make a syntax for this.

Moderocky avatar Apr 15 '24 06:04 Moderocky

I think I'd rather fix the function return behaviour than make a syntax for this.

there is no bug in function return behavior is works how it's intended to

Fusezion avatar Apr 15 '24 06:04 Fusezion

there is no bug in function return behavior is works how it's intended to

And I'm saying the behaviour is poor and could be done better.

Moderocky avatar Apr 15 '24 06:04 Moderocky

I don't much like this addition as Functions are better fit for this.

AyhamAl-Ali avatar Apr 15 '24 06:04 AyhamAl-Ali

I don't much like this addition as Functions are better fit for this.

Same could be said about the ExprRound class for rounded [1:up|2:down] %numbers%. This would work as a function if functions actually supported isSingle checks which rolls into Moderocky's mention.

And I'm saying the behaviour is poor and could be done better.

It can't be done better when the function literally can't support set {_blah} to clamp(10.6, 1, 10) this isn't exclusive to clamp when round function has the same flaw.

Fusezion avatar Apr 15 '24 07:04 Fusezion

It can't be done better when the function literally can't support set {_blah} to clamp(10.6, 1, 10) this isn't exclusive to clamp when round function has the same flaw.

Maybe I didn't make it clear, I am recommending we fix the issue with variable arity returns not being permitted in single changers. This would make all such functions work.

Moderocky avatar Apr 15 '24 07:04 Moderocky

I was looking over the clamp function tests but got confused by these three.

assert clamp(1, 0, NaN value) is not clamp(1, 0, NaN value) with "(single ints) min < value < NaN"
assert clamp(1, NaN value, 2) is not clamp(1, NaN value, 2) with "(single ints) NaN < value < max"
assert clamp(NaN value, 1, 2) is not clamp(NaN value, 1, 2) with "(single ints) min < NaN < max"

Why are they getting compared to themselves? I feel like these should be checking if the output is set.

Phill310 avatar Apr 27 '24 15:04 Phill310

Why are they getting compared to themselves? I feel like these should be checking if the output is set.

If I remember correctly this was one of the ways to check for 'not a number' because it didn't test equal to itself. I don't know if that's still the case anymore and we may have a better way.

Moderocky avatar Apr 27 '24 15:04 Moderocky

Why are they getting compared to themselves? I feel like these should be checking if the output is set.

If I remember correctly this was one of the ways to check for 'not a number' because it didn't test equal to itself. I don't know if that's still the case anymore and we may have a better way.

yes we have isNaN() now!

sovdeeth avatar Apr 27 '24 16:04 sovdeeth

In that case should it become assert isNaN(clamp(1, 0, NaN value)) is true with "(single ints) min < value < NaN"? Or do we want it to be false. I don't really understand what the old check was aiming for

Phill310 avatar Apr 27 '24 16:04 Phill310

In that case should it become assert isNaN(clamp(1, 0, NaN value)) is true with "(single ints) min < value < NaN"? Or do we want it to be false. I don't really understand what the old check was aiming for

yes exactly The original test took advantage of the fact that NaN does not equal NaN, but any other value should equal itself, to test for NaN

sovdeeth avatar Apr 27 '24 16:04 sovdeeth

Do we still want to move ahead with this now that the function is fixed? I like having the clamped above/below syntax.

sovdeeth avatar May 31 '24 18:05 sovdeeth