Is there a way to turn a number into 0 if it’s negative, but leave it alone if it’s positive?
For example, if I have the following formula:
(4-(10/2))
The result would be -1. But say, due to some randomness, the result was instead +2? Is there something I can do so that if the result is -1, it changes to 0, but if it’s +2, it stays as +2?
You can use the preformatted text button in the options when posting to include the code in boxes like below:
*rand x 1 3
*if ((x-round(((y-z)/2)))<0)
*set (x-round(((y-z)/2))) 0
*set w -(x-round(((y-z)/2)))
So one thing that is wrong here is that this line in particular (the one inside the *if):
*set (x-round(((y-z)/2))) 0
Has no variable being assigned the value of 0 (I’m assuming that’s hat you wanted to do?), so it wouldn’t really work; a variable must receive the value.
*set variable what_to_receive
And also what exactly that goes wrong? Is there an error message or just the calculations don’t amount to what you want?
I didn’t really understand what you were trying to do. I’m guessing you want to check if the equation is lower than 0, if so, set it to be 0. Then subtract w with the result of the equation? That’s what I got from it at least.
First, it’s better if we separate things for clarity. Let’s use result variable to receive your equation results first.
Then we compare if it’s less than 0. If so, set it to be 0.
Since subtracting something by 0 won’t matter, I added the *else.
If result is a positive number it will go through the *else and subtract w. Is this what you wanted to do? Or did you wanted w to receive the reverse of the result?
*temp result 0
*rand x 1 3
*set result (x-round(((y-z)/2)))
*if (result <= 0)
*set w 0
*else
*set w - result