Here you\'ll find tutorials that don\'t belong to either of the above categories. This is the place for the most extraordinary materials.  Home Photoshop Miscellaneous Photoshop Scripting Basics: Scripting for Photoshop

Photoshop Scripting Basics: Scripting for Photoshop

Browse Pages: << < 1  2  3  4  5  > >>

Operators

Operators are the same thing as arithmetic operators (+, -, *, /) and can be use to create equations in a script. Lets create a simple script using variables and operators.

var myNum = 6;
var myNum2 = 4;
1. We'll need three parts to create this equation:
  1. Two number variables to define the numbers that will be added
  2. A variable with the equation
  3. An alert function to test the script

Begin by defining the two variables.


var myNum = 6;
var myNum2 = 4;
var answer
2. Now we need to type in an equation. For starters, lets create one that adds the two variables.

Begin by creating a variable. We'll call this variable "answer".


var myNum = 6;
var myNum2 = 4;
var answer = myNum + myNum2;
3. We now need to define what the sum variable is. Simply type in the first variable (myNum) followed by the operator (+) and finally the second variable (myNum2).

var myNum = 6;
var myNum2 = 4;
var answer = myNum + myNum2;
alert(answer);
4. Lets test the variable by creating an alert pop-up with the variable. To do this, type in alert(), add the answer variable inside the parenthesis and type a ; to instruction the instruciton.

image 3 5. Save your file as a *.jsx file on your desktop. You can name it whatever you want. Open Photoshop and run the file (File> Scripts> Browse). an alert pop-up should popup with the answer to 6+4.

FAQ:
Q: What happens when you try to add strings instead of numbers?
A: JavaScript will try to convert the string to a number. For example, if your string is "5", it'll recognize that it's the number 5. However, if your string is "myString", it'll return an error with the NaN value which stands for "Not a Number".

Tip:
When only adding or subtracting one (ex. myVar + 1), you can simply type in "myVar ++" to increase "myVar" by 1 or "myVar decrease to decrase "myVar" by 1. This works the same as "myVar + 1" or "myVar - 1". Using increment or decrement will make your code cleaner and easier to read.



Author's URL: FotoFects
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
Browse Pages: << < 1  2  3  4  5  > >>
print this page subscribe to newsletter subscribe to rss

Advance your current skills or acquire new skills in Photoshop by creating projects using our step-by-step tutorials. More Tutorials: Most Popular Materials | Fresh Materials | TutorialKit New Photoshop Tutorials

Add comments to "Photoshop Scripting Basics: Scripting for Photoshop"

Only registered users can write comment

No comments yet...