Programs, Functions, Libraries

Each program corresponds to an autonomous execution sequence. Syntactically each program will be defined exactly like a function. However, with a fix function name main() and without return value (void) - generally also without parameters.

As in each higher programming language, CONTROL also allows the easy reuse of more often required program parts. Such sub programs are called as in the ANSI-C. These functions exist in two basic forms:

Each function that returns exactly an individual return value in the form of its function value, corresponds to a function.

If such a program provides several return values (the function value can also be among them), it is strictly speaking called a procedure in the software engineering.

An essential element of such sub programs is that you only have to define them once and you can call them in different programs in different parts. You do not have to embed the code again. When the program is called, locally in the program defined variables or constants will be passed to the function. The parameters passed in a call, are called "Actual parameters" whereas when defining them, they are called "Formal parameters".

Exactly one actual parameter of the calling program corresponds to a formal parameter used when programming.

All these connections are described in the descriptions of the program language C. This example merely shows the basic functionality.

main() // Main program starts here
  float a, b, c; // Variable declarations
  a = 10; // Assignments
  b = 14;
  c = sumFunction(a, b); /* Function call with a return value; Pass two actual parameters
  scaleValues(a, b, c, 1.5);// Call of a procedure function
  // with several return values
  // a, b and c are changed through the call
  DebugN(a, b, c); // Output of the results in the LogViewer
  // or Log file: a = 15, b = 21, c = 36 
// End of the main program
/* Declaration of the function with specification of the data type of the return value
float sumFunction(float summand1, float summand2) // Formal parameter
  // m. Type declaration
  float sum;
  sum = summand1 + summand2; // Use of the Formal parameter like
  / Variables in Program code
  return sum; // Return of the result (value of the
  // variable sum) to the calling procedure.
// Declaration of the Function with several return values
int scaleValues(float &a, float &b, float &c, float factor)
  // '&' defined:value will be
  a = a * factor; // returned
  b = b * factor;
  c = c * factor;
  if ((a == 0) || (b == 0) || (c == 0)) // Optionally a function
  return 0; // return value can provide
  else // information about
  return 1; // errors
The passed actual parameters in their order correspond exactly the formal
parameters of the declaration of the function. Alternatively, you could also implement
the first function a little bit more narrow and more efficient - as you can see, you can
save additional parameters by nesting expressions .
float sumFunction(float summand1, float summand2) 
  return summand1 + summand2; // Return value directly as expression

When calling the function scaleValues(), the return function value (data type int) which was provided in the declaration was not considered. In order to evaluate this too, the call could look as follows:

if (scaleValues(a, b, c, 1.5) > 0)




Thereby, the function is called first and subsequently its return value will be compared in the control expression of the if construct.

In addition to the here described parameters, there are also so-called default parameters in CONTROL. Thereby, a predefined parameter value will be defined already when declaring the parameter. You can also create functions with an arbitrary number of parameters.

Where the function is declared specifies the range of its availability for other functions:

  • Script local functions: if you declare a function directly below the main program, for example, within an EventScript, the function will be valid within the main program and in the functions declared within the main program.

  • Panel global functions: if you declare a function in the "general" part of the property sheet (events tab) for the panel object, you can use it in all scripts for all graphic objects (shapes).

  • Manager global functions: will be declared in independent libraries. These libraries are expected in the text files in the sub directory .../scripts/libsof the project hierarchy and must be loaded for the favored manager using the configuration fileconfig.level.