GPC Developer Guides

Basic GPC Structure

a gpc script can be split into sections there can be a total of 9 different sections and, in any user made script, they should be laid out in the order shown in the example below only the main section is mandatory as it is the heart of any script and is run in a constant loop definitions the define is used to assign a value to a word, creating a named constant definitions can be placed anywhere except inside the init , main , a combo , or function in this example, we define zero, one, and two as the values 0, 1, and 2 respectively these are static values that cannot be altered during run time so, should we use the word 'one' at any point in the script it is the same as typing the number 1 gpc // definitions section (optional) define zero = 0; define one = 1; define two = 2; for more detailed information, check out the definitions https //beta cronusmax com/gpc/gpc scripting definitions page data the data section is an array of bytes (8 bit integer) that is placed at the start of the virtual address space in gpc bytecode the values are read only and cannot be altered at run time the user can access these values via the zero based data array gpc // data section (optional) data (zero, one, two, 10, 128, 40); for example in this script we could do this to access the array gpc example4 = duint8(4); //example4 = 128 for more detailed information, check out the data section docid\ tqq0l5av7qdvste87mpzg page const arrays the const array section is similar to the data section, except it's easier to manage as you let the compiler track where the data is stored under the hood it uses the data section, but in a different way const arrays consist of 2 different types, one dimension and multi dimensional the difference between them is how the data is structured/accessed, see below for how they're defined gpc const int8 single\[] = { 0, 1, 2, 3 }; const int8 two dimensional\[]\[] = { { 0, 1, 2 }, { 3, 4, 5 } }; for more detailed information, check out the const arrays docid\ l1fyda8p1s2ofbth4pzga page remap in this section, we can alter the behavior of the controls with remap in this example, we are telling the virtual machine that a value assigned to the left bumper should be sent to the right bumper instead and vice versa gpc // remapping section (optional) remap xb1 lb > xb1 rb; remap xb1 rb > xb1 lb; it is important to note that button remaps are applied once the main has finished and just before the output report is sent to the console this means scripting should be programmed without considering the remapping for example, if at some point in this script we were to set the left bumper to 100 like so gpc set val(xb1 lb, 100); when the main procedure finishes, the output report would initially contain a value of 100 for the left bumper when the remaps are processed, this value would then instead be assigned to the right bumper and the output report would be modified when the final output report is sent to the console, it would contain a value of 100 for the right bumper instead of the left for more detailed information, check out the remapping docid\ fuei vqmkjvg3olyuxnj5 page variables a variable is a point in the stack memory where a value can be placed anywhere except inside of the main{} combo{} or function() these variables are global and gpc and can be accessed at any point within the script variables are not static and can be altered during run time if a variable is not assigned a value in this section, it is initialized with the value 0 such as the variables example2 and example3 in this script gpc // variable initialization section (optional) int example1 = 10; int example2, example3; int example4 = 17; for more detailed information, check out the variables docid\ vnk j2feeytw ux3wym4r page init the init section is similar to main with the exception that it is only run once when the script is loaded into the virtual machine it can run the same commands and functions as the main section such as combos and user created functions it is generally used to populate variables and arrays to set up the script in this example, if the cronus zen has a ps4 controller connected when the script is first loaded, example2 is assigned a value of 27 otherwise, it is assigned a value of 1 gpc // gpc initialization section (optional) init { if(get controller() == pio ps4){ example2 = 27; } else { example2 = 1; } } for more detailed information, check out the init section docid\ nz4xl05jz1zqu9dd1jzh5 page main the main section is the heart and soul of any gpc script, all functions and combos are initially executed from this section it is the only mandatory section and every gpc script must have one unlike combos and user created functions, a gpc may only have one main section and it is run in a loop the virtual machine runs through the code in order and generates an output report as it goes when the virtual machine gets to the end of the main section, the output report is then ready to be sent to the console once the console requests new data, the output report is sent and the main starts another run gpc // gpc main section (mandatory) main { if(example function()){ if(get val(example3)){ combo run(testing); } } } as commands are run through in order, setting the value of a button in more than one place means that only the last command is sent for example, in this script, a value of 100 for the ly axis will be sent to the console the console will not see the ly axis set to 100 because the output report for that control is modified again before it is sent to the console gpc main { set val(xb1 ly, 100); set val(xb1 ly, 100); } for more detailed information, check out the main section docid\ wcdbh9h0ggmrmgwtiyni3 page combo a combo is a function that will perform a set of instructions in order and for the amount of time assigned to the wait command directly after the commands in this script, when the combo is run, it will set identifier 20 (x on an xbox controller or square on a playstation controller) to 100% (fully pressed) for the time set in the variable example1 (10 milliseconds in this case) and then do nothing for 100 milliseconds gpc // combo section (optional) combo testing{ set val(20, 100); wait(example1); wait(100); } you can assign multiple commands before a single wait statement for example, in the following combo , both the left bumper and right trigger will be pressed for 500 milliseconds (half a second) when the combo is run it will then do nothing for 500 milliseconds gpc combo lb and rt { set val(xb1 lb, 100); set val(xb1 rt, 100); wait (500); wait (500); } for more detailed information, check out the combo section docid\ fsqutpqf zgopnjjyp6u8 page function a user created function is similar to the main section commands are processed in order and any gpc which is valid in the main section can be used here functions must be placed at the end of the gpc script the main difference with functions is they are only run when called and can return a value when a value is returned from a function , it is terminated and any code beyond that point is not executed gpc user functions are global, this means that can be called from the init , main and combo sections a function can even be called from within another function gpc // function section (optional) function example function(){ if(get val(example2)){ example3 = 18; return 1; } else if(get val(example4)){ example3 = 19; return 1; } return 0; } putting it all together gpc // definitions section (optional) define zero = 0; define one = 1; define two = 2; // data section (optional) data (zero, one, two, 10, 128, 40); // const array section (optional) const int8 single\[] = { 0, 1, 2, 3 }; const int8 two dimensional\[]\[] = { { 0, 1, 2 }, { 3, 4, 5 } }; // remapping section (optional) remap xb1 lb > xb1 rb; remap xb1 rb > xb1 lb; // variable initialization section (optional) int example1 = 10; int example2, example3; int example4 = 17; // gpc initialization section (optional) init { if(get controller() == pio ps4){ example2 = 27; } else { example2 = 1; } } // gpc main section (mandatory) main { if(example function()){ if(get val(example3)){ combo run(testing); } } } // combo section (optional) combo testing{ set val(20, 100); wait(example1); wait(100); } // function section (optional) function example function(){ if(get val(example2)){ example3 = 18; return 1; } else if(get val(example4)){ example3 = 19; return 1; } return 0; }