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

How to change variable type

Guest
May 22, 2014 May 22, 2014

Hi I am starting to write a script to draw an image with different dimensions that I can input.

so Here is what I have so far:

// Create Window

var StartingPointWindow = new Window ("dialog", "Form");

// Add text: "Starting Point X:" to window

StartingPointWindow.add ("statictext", undefined, "Start Point X:");

var inputX=0;

//Add edit text box

var StartPointX = StartingPointWindow.add ("edittext", undefined, inputX);

// Ready to enter text

StartPointX.active = true;

// Maximm charicters 5

StartPointX.characters = 5;

// add OK and Cancel button

StartingPointWindow .add ("button", undefined, "ok");

StartingPointWindow .add ("button", undefined, "Cancel");

if (StartingPointWindow.show () == 1)

{  

    StartingPointWindow.close(StartPointX.SAVECHANGES);

    inputX= StartPointX.contents;

//   inputX.append (String.to Number)

   var docRef = documents.add();

   var piRef = activeDocument.pathItems;

   var pathRef = piRef.add();

//Draw line from points (X,Y) to (X,Y)

  pathRef.setEntirePath( new Array(

  new Array((inputX), (200)),

  new Array((400), (500)) ) ) ;

}

//PresrtPointX changes

else{

StartingPointWindow.close( StartPointX.DONOTSAVECHANGES );

}

So this my starting point for some testing but the problem I seem to have is that it wont accept the inputX variable on line 48 - I think this because the edittext is saving the input number as a string? I may be wrong so any help would be appreciated.

Many Thanks

TOPICS
Scripting
311
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
Adobe
Guru ,
May 22, 2014 May 22, 2014

I doubt it's a variable type issue…! You can always parseFloat( foo ), parseInt( foo ) or Number( foo )…

You have created a window of dialog type… This must be dismissed before you can continue with your script…

Step 1 create window…

On OK collect user input data to ( Object )

Step 2 pass Object to main script function…

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 ,
May 22, 2014 May 22, 2014
LATEST

couple of issues, what you suspect is true, the value returned by the edittext is a String, so convert that to a Number.

the other thing is, in line 35, "contents" is not a valid property, change that to "text"

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