how to make a variable absolute value

I need absolute value to make a negative into positive. Does anyone know how to do a scriptcall for this?
There's a JavaScript function for that: Math.abs(value).
As for how to get the value: $gameVariables.value(x) where x is the ID of the variable.

For example, if you're trying to get the absolute value of variable #0003:
JavaScript:
Math.abs($gameVariables.value(3))

I've seen people use things like $gameVariables.value(0003), but you should avoid prepending zeroes in front of the ID. In JavaScript, a number that starts with zero would cause either outcome:
  • If using strict mode, this will cause an error.
  • If not using strict mode, the number will be interpreted as an octal number, where 010 is the octal representation of 8.
So basically don't prepend a zero in front of a number. If you really intend to use octal values, prepend 0o (zero-o) instead, so 0o10 is the octal representation of 8. That will also work in strict mode, since if you start a number with 0o, you probably know what you're doing.
Another option would be to set the value manually instead of using the Math.abs() function. Either way works just fine.

Code:
$gameVariables.setValue(id, -$gameVariables.value(id))

In this instance, both "id" in the setup would be the same, and using this you can swap a pos->neg or a neg->pos easily.

Like I said, just another possible option 😀
And if you want to do it with just event commands, some simple logic:
Conditional Branch -> Variable X < 0
--Control Variable -> X -> Mul -> Constant -> -1

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-variable-absolute-value.152262/