User Created Functions

User Created Functions

As well as having a significant number of built in functions, GPC allows the user to create their own custom functions. A function can run any code valid in the main section and code is also executed in the order it is written.

main {
    
    if (get_val(PS4_CROSS)) {                    // If we get a value other than 0 from A / CROSS...
        if (myfunction(10,20) == 30) {           // If myfunction returns a value of 30
            combo_run(mycombo);                  // run combo mycombo
        }
        else if (myfunction(10, 20) == -10) {    // If myfunction returns a value of -10
            combo_stop(mycombo);                 // stop mycombo if it is running
        }
    }

}

combo mycombo {
    set_val(PS4_TRIANGLE, 100);
    wait(1000);
    wait(1000);
}

function myfunction(_1stvalue, _2ndvalue) {      // myfunction start

    if (get_val(PS4_CIRCLE)) {                   // If we get a value other than 0 from B / Circle...
        return _1stvalue + _2ndvalue;            // return '_1stvalue' plus '_2ndvalue'
    }
    return _1stvalue - _2ndvalue;                // other '_1stvalue' - '_2ndvalue'
}

Calling a Function

myfunction(10,20);

To call (or run) a function, you simply type its name and put any parameters it requires in between ( and ).

When a function is called, the code within it is executed and the return value is sent back to where it was called from.

User functions are what is known as global scope, this means they can be called from the init, main and combo sections. They can even be called from within another function, however, GPC does not support recursive calls of functions. This means a function cannot be called from within itself.

Last updated