GPC Developer Guides

Variables

as of firmware version 2 1 0, all variables in gpc are both 16 bit and 32 bit signed integers an integer (from the latin integer which means whole ) is a number that can be written without a fractional component for example, 0, 20, 128, and 1000 are all integers while 4 2, 5 6, or 110 9 are not 16 bit signed means the variables can store any value ranging from 32,768 to +32,767 32 bit signed means the variables can store any value ranging from 2,147,483,648 to +2,147,483,647 important gpc lacks support for fractions and instead rounds them down 3 6 would be rounded down to 3 declaring variables a variable is a place where data can be stored in the memory of a virtual machine variable names can start with either an underscore ( ) or a letter and can be followed by any combination of letters, digits or underscores they are case sensitive, so "cronuszen", "cronuszen" and "cronuszen" would specify three different variables variables defined this way in gpc are global, this means they can be accessed and modified within the init or main sections as well as a combo or function only variables assigned to user created functions are local details of how variables operate within user functions can be found in the user created functions docid\ yvybjabmpc9t40ecedfsk section global variables must be declared outside of the main or init sections and therefore cannot be declared in either of those sections, as shown below gpc int myvar = 100, myvar; int myvar = 40; init { //int incorrect; //this will cause an error } int incorrect; //this will also cause an error main { //int incorrect; //this will again cause an error } info variables are always assigned a value if no value is assigned when they are declared, they are initialized with a value of 0 (zero) the value assigned to a variable can be altered during runtime, as shown below gpc int myvar = 100, myvar; // myvar initial value is 100, myvar initial value is 0 int myvar = 40; // myvar initial value is 40 main { myvar = myvar myvar; // myvar value is now 60 } boolean variables unlike other programming languages, such as c# for example, gpc does not require a separate variable type for boolean values the integers in gpc have been designed to support boolean expressions the keywords true and false have been assigned the values 1 and 0 respectively as shown in the example below; gpc int myvar, myvar; main { myvar = true; //myvar = 1 myvar = false; //myvar = 0; } info you can therefore use integers in your code to create a toggle switch that enables or disables sections of code, like so; gpc int myvar; main { if(event press(xb360 a)) { //if a is pressed on the controller myvar = !myvar; // here we assign myvar to the opposite of the truthy value of myvar meaning if it's 0 // it's value will be set to 1, otherwise it's going to be 0 } if(myvar) { //if myvar has a value other than 0 (zero) //do something } } info as seen in the above example, a variable will return true in an if statement if it has any value other than 0 (zero) you can however use operators should you wish for your code to only be active if a variable has a certain value; gpc int myvar; main { if(event press(xb360 a)) { // if a is pressed on the controller myvar = myvar + 1; // increment myvar by 1 } if(event press(xb360 x)) { // if x is pressed on the controller myvar = myvar 1; // decrement myvar by 1 } if(myvar == 2) { // if myvar has a value of 2 //do something } if(myvar >= 4) { // if mvar has a value of greater than or equal to 4 //do something } if(myvar < 2) { // if mvar has a value less than 2 //do something } }