Software
Crestron
SIMPL+
This code causes a compile error, because the function
MyUserFunction1
has been
called before it has been defined. This can easily be remedied by reversing the order:
INTEGER x;
FUNCTION MyUserFunction1()
{
print("This is MyFunction1 runnning!\n");
}
INTEGER_FUNCTION MyUserFunction2( INTEGER arg1, STRING arg2 )
{
print("This is MyFunction2 runnning!\n");
}
PUSH someSignal
{
call
MyUserFunction1();
x = MyUserFunction2( x, 10 );
}
This program compiles without any problems. Due to this dependence on order, the
SIMPL+ module template that appears each time a new program is created provides
a place to put function definitions. Notice that this section comes after the
input/output and variable definitions, but before the event and main functions.
Following the layout suggested by the template should prevent most of these errors.
Defining Local Variables In Functions
The concept of local variables was introduced in the section "All About Variables".
In this section we will discuss the topic in greater detail and present a number of
examples.
What is a local variable? A local variable is a variable (i.e. an integer or string) with
a limited "life span" and limited "scope." You can think of global variables as being
immortal. That is, for as long as the control system is plugged in and the program is
running, global variables retain their values unless a programming statement
modifies them. In addition, global variables can be accessed (either to use their value
or to modify them) anywhere in a SIMPL+ program. Here is a simple example:
DIGITAL_INPUT go;
INTEGER i,j,k; // define 3 global integers
FUNCTION sillyFunction()
{
i = j * 2;
k = i – 1;
}
FUNCTION anotherSillyFunction()
{
j = i + k;
}
PUSH go
{
i = 1;
j = 2;
k = 3;
34
•
SIMPL+
Programming Guide – DOC. 5789A