> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/variables.md).

# Variables

## 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.

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](/gpcscripting/gpc-script-guide/gpc-developer-guide/user-created-functions.md) 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 myvar1 = 100, myvar2;
int myvar3 = 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
}
```

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 myvar1 = 100, myvar2;    // myvar1 initial value is 100, myvar2 initial value is 0
int myvar3 = 40;              // myvar3 initial value is 40

main {
    myvar3 = myvar1 - myvar3; // myvar3 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 myvar1, myvar2;

main {
    myvar1 = TRUE;     //myvar1 = 1
    myvar2 = FALSE;    //myvar2 = 0;
}
```

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

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 myvar has a value of greater than or equal to 4
        //do something
    }
    if(myvar < 2) {                  // if myvar has a value less than 2
        //do something
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
