Page 1 of 1

[Solved]How to make a number positive

Posted: Fri May 03, 2024 3:32 am
by VirtualPassion
I'm making a mini game in a visual novel. I have an object moving on the screen. And there is a second object that the player controls. If the difference between the coordinates of the first and the second object is small, the player loses.
The difference between the objects can be either positive or negative. How can I make the negative value positive to compare with the critical value?

Re: How to make a number positive

Posted: Fri May 03, 2024 4:04 am
by m_from_space
VirtualPassion wrote: Fri May 03, 2024 3:32 am I'm making a mini game in a visual novel. I have an object moving on the screen. And there is a second object that the player controls. If the difference between the coordinates of the first and the second object is small, the player loses.
The difference between the objects can be either positive or negative. How can I make the negative value positive to compare with the critical value?
Don't know if that is what you want, but making a negative value positive is easy using the abs() function:

Code: Select all

$ positive_number = abs(-100)

Re: How to make a number positive

Posted: Fri May 03, 2024 6:19 am
by VirtualPassion
Thank you. Turns out I was just confused about the brackets.

Code: Select all

If((((coocker_posy>0.41)or(coocker_posy<0.39))and(abs(food1_pos-coocker_posx)<0.10)),

Re: How to make a number positive

Posted: Fri May 03, 2024 6:39 am
by m_from_space
VirtualPassion wrote: Fri May 03, 2024 6:19 am Thank you. Turns out I was just confused about the brackets.

Code: Select all

If((((coocker_posy>0.41)or(coocker_posy<0.39))and(abs(food1_pos-coocker_posx)<0.10)),
Not sure if you're a former LISP coder, but you don't need that many brackets. So you are not getting confused as easily. ^^

Code: Select all

if (coocker_posy > 0.41 or coocker_posy < 0.39) and abs(food1_pos - coocker_posx) < 0.1: