This tutorial
provides step by step instruction on how to create and run a very
simple 'Hello World' type of script. It will illustrate the basics
of how to create and use a variable and
how to display information to the screen.
Start by opening a standard ASCII text editor. Create a new file and
save it as "HelloWorld.psc" in the same directory as where
your Phantom Interpreter (phantom.exe) is installed.
The first line of the script will be a comment. Comments
are indicated by a '#' character. Anything after the '#' character in
a line of script code is ignored by the Phantom interpreter.
Example
Code |
Line |
Code |
1 |
#
This is a simple Phantom script |
Next, a single string variable will be created. This will be done using
the type 'string' and giving the variable a name, 's'. Initially, the
variable contains nothing but an empty string. Later the string will
be given a value.
Example
Code |
Line |
Code |
1
2
3
4 |
#
This is a simple Phantom script
# Declare a string variable
string s; |
To give the string a value, use the name 's' followed by the equal sign
(=), followed by the value. Note that the value for a string must be
in quotes. Other variable types have values represented in different
ways. See Variables for more information.
Example
Code |
Line |
Code |
1
2
3
4
5
6
7 |
#
This is a simple Phantom script
# Declare a string variable
string s;
# Give the variable a value
s = "Hello World!"; |
Finally, display the value of the string 's' to the screen. This is
done using the 'disp' function. For
the DOS version of Phantom, the 'disp' function displays a value to
the DOS console.
Example
Code |
Line |
Code |
1
2
3
4
5
6
7
8
9
10 |
#
This is a simple Phantom script
# Declare a string variable
string s;
# Give the variable a value
s = "Hello World!";
# Display the variable to the screen
disp(s); |
That's all there is to a simple 'Hello World' script. Save the script
in the editor as "HelloWorld.psc" if not already done. The
script should be saved in the same folder where the phantom.exe executable
is located.
Now, run the script by opening a DOS console. If you are using Windows
98 or before, click Start, then 'Run'. Then type 'command' in the run
box and hit enter. This will open the console window.
If you are running a windows version later than Windows 98, click Start,
then 'Run', and then enter 'cmd' in the run box. In Windows Vista, type
'cmd' in the search box after clicking 'Start'.
Once the console is open, navigate to the folder where phantom.exe is
located. Then enter the following:
phantom.exe HelloWorld.psc
This will run the HelloWorld script just created. The output should
look like:
Output |
FileName
is: HelloWorld.psc
-----------------------------------------
| Phantom v2.0 |
| http://www.phantomtest.com
|
| This DOS version is freeware
|
| Type 'stop' to quit.
|
-----------------------------------------
Hello World! |
An alternative to going through the console is to simply double-click
on the phantom.exe icon. This will open phantom in
console mode.
In console mode, the script can be run by entering the include
keyword, followed by the name of the script:
Output |
-----------------------------------------
| Phantom v2.0 |
| http://www.phantomtest.com
|
| This DOS version is freeware
|
| Type 'stop' to quit.
|
-----------------------------------------
1 >> include "HelloWorld.psc";
Hello World!
2 >> |
That's it! You have created and run your first HelloWorld script. Many
of the examples in this documentation are stand-alone scripts that can
be run just like this HelloWorld script was. Simply take the example
code and place it in a file and save it. Then run it using Phantom.exe
as described above. Note that any examples with code preceded by line
numbers (1 >>, 2 >>, etc...) are console examples. Remove
the line numbers (1 >>, 2 >>, etc...) to use the commands
in a script.
The next tutorial illustrates
how to do a simple automation Hello World.