GenerativeComponents Help

Writing our own global functions

Global functions can be created by using the global keyword. For example:

	global int Plus(int x, int y) { return x + y; }

This creates a new global function that's just like the built-in functions. It's not associated with the current graph, and (therefore) it persists through the entire session, regardless of opening/creating transaction files.

While we're on the subject, the user can also create global variables:

	global double Tolerance = 0.01;

Like global functions, global variables persist through the entire session.

Here is an example of defining and then running the function 'Plus'.

To view the output of this function you must open the (Console ) window. After the transaction successfully runs, you can follow the following steps to see if the function 'Plus' was successfully created:
  1. Select (Show Functions ) to access the functions.
  2. In the Functions dialog use the scroll bar to search for the created function 'Plus'. The listed functions should be alphabetically sorted.
  3. Once found, click on the Plus function and you can view the function that was previously declared in the transaction.
This function will exist and be usable until the end of the session.
transaction 1 script 'Create and Run Global Function'
{
    global redeclare int Plus(int x, int y) {return x + y;};
    Print("When you add 6 and 7 you get " + Plus(6,7));
}