User-defined Functions

A function may be defined using syntax such as the following:
function foo(arg_1, arg_2, /* ..., */ arg_n)
    // Example of a function
    return arg_1;
      Any valid GPC code may appear inside a function, even other functions. Function names follow the same rules as variables. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
      Functions must be defined at the very end of the script code, after the main procedure and combo definitions. All functions in GPC have global scope - they can be called inside of init and main procedures and even inside other functions. GPC does not support recursive calls of functions.

  1. Function Arguments

      Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. The arguments are evaluated from left to right. Note that is NOT necessary specify the data type of a parameter, since GPC supports one data type (int).
      All arguments are passed by its value, GPC does not support passing arguments by reference. So as, if the value of an argument is changed inside the function, it does not get changed outside of the function.

  2. Returning Values

      Values are returned by using the optional return statement. This causes the function to end its execution immediately and pass control back to the line from which it was called. If the return is omitted the value 0 will be returned.

  3. Example of Use

int result;
main {
    result = sum(10, 20);
    set_val(TRACE_1, result);
function sum(a, b) {
    return a + b;