[Solved]How to make a number positive

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
VirtualPassion
Newbie
Posts: 10
Joined: Wed Feb 28, 2024 3:10 am
Deviantart: virdate
itch: virtual-passion
Contact:

[Solved]How to make a number positive

#1 Post 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?
Last edited by VirtualPassion on Fri May 03, 2024 6:22 am, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1006
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to make a number positive

#2 Post 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)

VirtualPassion
Newbie
Posts: 10
Joined: Wed Feb 28, 2024 3:10 am
Deviantart: virdate
itch: virtual-passion
Contact:

Re: How to make a number positive

#3 Post 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)),

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1006
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to make a number positive

#4 Post 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:

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]