# Move value towards 0?

### » Mon Oct 27, 2008 12:02 am

Is there a command that if a value is lower than 0 or greater than 0 it will add/subtract a certain amount. It would be a lot easier than having to make separate events.
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

### » Mon Oct 27, 2008 12:41 am

Wow you're lazy.
It just takes 2 events!
B
2
S
1
G
4
Posts: 92
Reputation: 1,384

### » Mon Oct 27, 2008 1:56 am

That'd be useful. But since I don't remember implementing such functionality in any game making tool / programming language, this kind of stuff would be hard to fit in.
My code's filled with ugly 3-evented "move value towards 0", Function object would simplify things a little.
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

### » Mon Oct 27, 2008 9:36 am

Wiki says that the system expression "sign(x)" returns x/abs(x) for non-zero numbers. That's -1 for negative numbers, +1 for positives. This suggests the following (untested) expression for "move from a given value towards zero by a specified amount":
[code:1dgemdxb]
Value-(sign(Value)*Amount)
[/code:1dgemdxb]
Note that this will "overshoot" zero if abs(Value) < Amount; e.g. with Value=1, Amount=2 you get -1.
B
2
S
1
G
4
Posts: 60
Reputation: 1,320