---
title: Variables
slug: gpc/gpc-scripting-variables
description: 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
docTags: 
createdAt: 2022-02-02T16:06:04.000Z
---

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&#x20;

32-bit signed means the variables can store any value ranging from -2,147,483,648 to +2,147,483,647

:::hint{type="danger"}
**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.&#x20;

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.&#x20;

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:

:::CodeblockTabs
GPC

```cpp
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
 
}
```
:::

:::hint{type="info"}
**Info:&#x20;**&#x56;ariables 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.
:::

:::CodeblockTabs
GPC

```cpp
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;

:::CodeblockTabs
GPC

```cpp
int myvar, MYVAR;
 
main {
 
    myvar = TRUE;   //myvar = 1
 
    MYVAR = FALSE;  //MYVAR = 0;
 
}
```
:::

:::hint{type="info"}
**Info:&#x20;**&#x59;ou can therefore use integers in your code to create a toggle switch that enables or disables sections of code, like so;
:::

:::CodeblockTabs
GPC

```cpp
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
 
    }
}
```
:::

:::hint{type="info"}
**Info:&#x20;**&#x41;s 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;
:::

:::CodeblockTabs
GPC

```apex
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
 
    }
 
}
```
:::

