Functions in GPC Code
Posted: Sat Aug 20, 2016 4:52 pm
I made this to hopefully explain a little better how functions work in GPC code. Any feedback is appreciated!
The best way to explain how the functions work is that they are almost exactly like a combo with the exception that they can create their own variable within the parenthesis located in the name. These variables can only be used within the function and if you don't send the correct information for the definition it will fail in compilation. In the example below it is LED(a, b, c, d) and the a b c and d are the variables. In order to use the function you call it in the same way as a combo except that at the end of the call you need to include the values that will be passed into the function. LED(value for a, value for b, value for c, value for d). I've included trace variables in the function itself so you can easily see the values passed in from the calls in main. This can be used in many ways and tremendously reduces code duplication. It is not always a replacement for combos, and is best used only when you have multiple different values that may have to be used by the same code routine. For example if you have different fire rates for rapid fire, or different values for anti-recoil. This would be a time to use functions as you could easily pass the parameters to the function without having to re-write the code for the rapid fire or anti-recoil. Please let me know if there are any other questions or if I could make this small tutorial on how to use functions a little better.
The best way to explain how the functions work is that they are almost exactly like a combo with the exception that they can create their own variable within the parenthesis located in the name. These variables can only be used within the function and if you don't send the correct information for the definition it will fail in compilation. In the example below it is LED(a, b, c, d) and the a b c and d are the variables. In order to use the function you call it in the same way as a combo except that at the end of the call you need to include the values that will be passed into the function. LED(value for a, value for b, value for c, value for d). I've included trace variables in the function itself so you can easily see the values passed in from the calls in main. This can be used in many ways and tremendously reduces code duplication. It is not always a replacement for combos, and is best used only when you have multiple different values that may have to be used by the same code routine. For example if you have different fire rates for rapid fire, or different values for anti-recoil. This would be a time to use functions as you could easily pass the parameters to the function without having to re-write the code for the rapid fire or anti-recoil. Please let me know if there are any other questions or if I could make this small tutorial on how to use functions a little better.
- Code: Select all
main {
if(event_press(PS4_CROSS)) LED(0, 0, 0, 0);
if(event_press(PS4_SQUARE)) LED(1, 0, 0, 0);
if(event_press(PS4_CIRCLE)) LED(0, 1, 0, 0);
if(event_press(PS4_TRIANGLE)) LED(0, 0, 1, 0);
if(event_press(PS4_DOWN)) LED(0, 0, 0, 1);
if(event_press(PS4_UP)) LED(1, 0, 1, 0);
if(event_press(PS4_R1)) LED(0, 1, 1, 0);
if(event_press(PS4_R2)) LED(1, 1, 1, 0);
}
function LED(a, b, c, d) {
set_led(0, a);
set_led(1, b);
set_led(2, c);
set_led(3, d);
set_val(TRACE_1, a);
set_val(TRACE_2, b);
set_val(TRACE_3, c);
set_val(TRACE_4, d);
}