Solved: sign function

Discussion and feedback on Construct 2

Post » Sat May 31, 2014 8:59 pm

sign(x)
return -1 or 1
Last edited by DAG on Wed Jun 25, 2014 1:55 pm, edited 1 time in total.
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Sat May 31, 2014 9:08 pm

Or you could use this instead...

abs(x) / x
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,286
Reputation: 47,556

Post » Sat May 31, 2014 9:13 pm

Colludium wrote:Or...

abs(x) / x


and then 0 came x)

for that I'd use the function object, or directly (x=0?0:abs(x)/x), but I agree that a sign function returning -1, 0 or 1 would be kind of nice for readeability.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Sat May 31, 2014 9:28 pm

@Aphrodite - very good point!! You've probably just saved me some pain in the future.... ;)
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,286
Reputation: 47,556

Post » Sat May 31, 2014 9:32 pm

But how is it useful?
Can you show where it would come in handy?
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Sat May 31, 2014 9:36 pm

@newt it's useful in tons of cases. Classic case, when you want to set a certain variable based on the x-component of movement, you'd use sign(x) on the vector and multiply that by a constant to create a multiplier for an animation speed or something.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Sat May 31, 2014 10:03 pm

Well its not supported in js by all the browsers, so I doubt it would get added, as conditionals handle it fairly well.
Exceptional examples help make exclusive expressions.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Sun Jun 01, 2014 3:51 am

+1 for me as well. I've had situations where it would've been handy to simplify some expressions.
Construct Classic had it and it's true that it could be done with existing expressions, but the same can be said for lerp, clamp, abs and probably others.

I also don't agree that it isn't supported everywhere, it can be done in js with just a few comparisons so it would work everywhere. Anyway, it isn't absolutely needed but I imagine it is as easy to add as qarp, cubic and cosp.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sun Jun 01, 2014 12:16 pm

I agree with r0j0hound, about the fact that it is not because it is easy that it shouldn t be included:

First: readeability, just reading Sign() is explicit enough, contrary to the other expressions we can set up for it
2nd: I had more trouble doing it that doing a lerp with expressions, because of the 0! And it is easy to forgot for a non mathematician guru than 0/0 does not exist (lerp does not need any conditionnal, it is a simple calculation, while Sign is not a calculation, but an evaluation at the end)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Sun Jun 01, 2014 3:24 pm

Well makes sense -0 & +0 are 0, I don't see the point
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,481

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 13 guests