Vectorials
Flash Perfection
3D Lessons
Tutorialkit
Markup Tutorials
Learn PHP
network
adv banner
Photoshop  Home Photoshop Miscellaneous Photoshop Scripting Basics: Variables
rss

Photoshop Scripting Basics: Variables

Author: FotoFects More by this author
Browse Pages: << <  1  2  3  4  5 > >>


Variables

Variables are used to store value for organizational purposes. For example, if you have the title "My Photos" used several time in a script, you can set that as a variable and every time you want to change the title, you can simply edit the variable instead the the entire script. Lets create a simple script using a variable. Open a text editor such as Notepad to type the code.

var 1. To begin, you need to tell Photoshop what you want to do. In this case, we want to create a variable and to create a variable, you can simply type in the keyword "var".

var myVar 2. Now we need to name the variable. Variable names can only contain alphanumeric characters and underscores. Lets call our variable "myVar" by typing it next to var. Variables are case-sensitive.

var myVar = "Hello World" 3. Now we need to tell Photoshop what we want the value of myVar to be. There are three types of values you can enter:
  • String - text or sentence. Strings must be enclosed in quotes ("")
  • Numbers - Numbers can be used in mathematical equations.
  • Booleans - true or false

Lets create a string variable called "Hello World!" by typing an = sign and then ""Hello World!"". Because this value is a string, don't forget to add the quotes.


var myVar = "Hello World!";
alert(myVar);
4. Finally, you need to end the instruction by simply adding a ; at the end.

Lets test the variable by creating an alert pop-up with the variable. To do this, type in alert(), add myVar inside the parenthesis and type a ; to instruction the instruciton.

image 2 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 dialog should popup with your variable as the text.


print this page tell a friend subscribe to newsletter subscribe to rss
Rate this Material: Bad 1 2 3 4 5 Excellent
Browse Pages: << <  1  2  3  4  5 > >>

Add comments to "Photoshop Scripting Basics: Variables"