Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

There is something simple about subtraction that has me stumped

Participant ,
Jan 16, 2023 Jan 16, 2023

In the following javascript code snippet, I am getting the negative of the desired result.  In other words, the results in the alert are  selCenterX - 3000.  and selCenterY - 3000.

 

alert(selCenterX,selCenterY);
	var distancetoMidpointX = (3000. - selCenterX);
	var distancetoMidpointY = (3000. - selCenterY);
alert(distancetoMidpointX,distancetoMidpointY);

Something simple I am sure.  Please help.

TOPICS
Actions and scripting
232
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 16, 2023 Jan 16, 2023

I can't check right now, but maybe the problem is that you don't specify the units for halfCanvas (your selCenterX and selCenterX are both have type 'px'), those something like:

 

halfCanvas = new UnitValue( "3000 pixels" )

 

Translate
Adobe
Community Expert ,
Jan 16, 2023 Jan 16, 2023

You seem to be using a comma in the alert where it does not quite belong. 

Try 

alert(distancetoMidpointX+","+distancetoMidpointY);

instead

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2023 Jan 16, 2023

Here is the latest code.  Still the same problem - the result is the negative of the correct answer.

alert(selCenterX+","+selCenterY);
	var halfCanvas = 3000.
	var distancetoMidpointX = (halfCanvas - selCenterX); // assumes a 6k by 6k canvas
	var distancetoMidpointY = (halfCanvas - selCenterY);
alert(distancetoMidpointX+","+distancetoMidpointY);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2023 Jan 16, 2023

This is what the alerts return:

alrt1.jpgalrt2.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 16, 2023 Jan 16, 2023

I can't check right now, but maybe the problem is that you don't specify the units for halfCanvas (your selCenterX and selCenterX are both have type 'px'), those something like:

 

halfCanvas = new UnitValue( "3000 pixels" )

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2023 Jan 16, 2023
LATEST

Excellent.  I would never have found this on my own.  The solution was not simple to a novice.

Thank you again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2023 Jan 16, 2023

I cannot reproduce the issue, please post the code properly. 

Screenshot 2023-01-16 at 18.09.27.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines