Global variables, Local variables, Global variables local variables – Teledyne LeCroy Merlins Wand - Users Manual User Manual

Page 274

Advertising
background image

258

CATC M

ERLIN

S

W

AND

2.00

C

HAPTER

D

User’s Manual

CATC Scripting Language

A variable is created when it is assigned a value. Variables can be of any
value type, and can change type with re-assignment. Values are assigned
using the assignment operator ( = ). The name of the variable goes on the
left side of the operator, and the value goes on the right:

x = [ 1, 2, 3 ]
New_value = x
name2 = "Smith"

If a variable is referenced before it is assigned a value, it evaluates to null.

There are two types of variables: global and local.

Global Variables

Global variables are defined outside of the scope of functions. Defining
global variables requires the use of the keyword set. Global variables are
visible throughout a file (and all files that it includes).

set Global = 10;

If an assignment in a function has a global as a left-hand value, a variable
will not be created, but the global variable will be changed. For example

set Global = 10;

Function()
{

Global = "cat";
Local = 20;

}

will create a local variable called Local, which will only be visible within
the function Function. Additionally, it will change the value of Global
to "cat", which will be visible to all functions. This will also change its
value type from an integer to a string.

Local Variables

Local variables are not declared. Instead, they are created as needed. Local
variables are created either by being in a function's parameter list, or simply
by being assigned a value in a function body.

Function(Parameter)
{

Local = 20;

}

Advertising