> 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/constants/persistent-memory.md).

# Persistent Memory

It is important to remember that each time this function is called, data is read from the EEPROM on the Cronus. The life of an EEPROM is typically rated in the amount of read/write cycles that can be performed and although the EEPROM in the Cronus is rated for 1000's of these, you should still ensure that this function is NOT going to call in every iteration of the main loop. Never use it at the base level of the main and always ensure it is nested within an if statement which will only return TRUE for one iteration, such as event\_press.

Persistence in programming means a state which remains after the process that created it has ended. For example, a word processor or paint application achieves this by saving the document to a file. The Cronus does this by writing variable values to its EEPROM (Electrically Erasable Programmable Read-Only Memory). This allows you to save the value of a variable so it can be recalled the next time the script is loaded.

There are a total of 512 persistent variables on the Cronus Zen (512 Private Variable).

Slot Persistent Variables, or SPVAR, are private to a specific memory slot. Each of the memory slots has 64 private variables, which are used to save specific values for one script. For example, Cronus Zen Slot 1 has 64 private variables which no other Slot can access, you cannot read or set the value of Slot 1's variables from Slot 4, and setting the private variables in Slot 1 will not have any effect on the private variables in any other slot. Constants have been created for use with the get and set commands for persistent variables, they are:

|           |           |           |           |
| --------- | --------- | --------- | --------- |
| SPVAR\_1  | SPVAR\_2  | SPVAR\_3  | SPVAR\_4  |
| SPVAR\_5  | SPVAR\_6  | SPVAR\_7  | SPVAR\_8  |
| SPVAR\_9  | SPVAR\_10 | SPVAR\_11 | SPVAR\_12 |
| SPVAR\_13 | SPVAR\_14 | SPVAR\_15 | SPVAR\_16 |

Cronus Zen has an additional 48 private variables bringing the total to 64, the additional private variable constants are listed below:

|           |           |           |           |
| --------- | --------- | --------- | --------- |
| SPVAR\_17 | SPVAR\_18 | SPVAR\_19 | SPVAR\_20 |
| SPVAR\_21 | SPVAR\_22 | SPVAR\_23 | SPVAR\_24 |
| SPVAR\_25 | SPVAR\_26 | SPVAR\_27 | SPVAR\_28 |
| SPVAR\_29 | SPVAR\_30 | SPVAR\_31 | SPVAR\_32 |
| SPVAR\_33 | SPVAR\_34 | SPVAR\_35 | SPVAR\_36 |
| SPVAR\_37 | SPVAR\_38 | SPVAR\_39 | SPVAR\_40 |
| SPVAR\_41 | SPVAR\_42 | SPVAR\_43 | SPVAR\_44 |
| SPVAR\_45 | SPVAR\_46 | SPVAR\_47 | SPVAR\_48 |
| SPVAR\_49 | SPVAR\_50 | SPVAR\_51 | SPVAR\_52 |
| SPVAR\_53 | SPVAR\_54 | SPVAR\_55 | SPVAR\_56 |
| SPVAR\_57 | SPVAR\_58 | SPVAR\_59 | SPVAR\_60 |
| SPVAR\_61 | SPVAR\_62 | SPVAR\_63 | SPVAR\_64 |

To retrieve the value stored in a persistent variable or to set the value of one, the following functions are available:

| **Function** | **Description**                                       | **Zen** | **Plus** |
| ------------ | ----------------------------------------------------- | ------- | -------- |
| get\_pvar    | Returns the value stored within a persistent variable | Yes     | Yes      |
| set\_pvar    | Stores a value into a persistent variable             | Yes     | Yes      |

***

### get\_pvar

get\_pvar returns the value stored in a Persistent Variable while allowing you to specify the minimum and maximum permissible value and a default value should the value stored be outside of that range. The min, max, and default parameters are mainly intended for when you are retrieving values from a Global variable, however, they must still be specified when reading the value of a private variable.

Code-Snippet

```
int a, b, c;

init {
    a = get_pvar(SPVAR_1, 0, 10, 5);
    b = get_pvar(SPVAR_2, 20, 40, 30);
    c = get_pvar(SPVAR_3, -30, 400, 100);
}

main {

}
```

Syntax

get\_pvar ( \<pvar\_constant>, \<min\_value>, \<max\_value>, \<default\_value> )

Parameters

\<pvar\_constant> : A global or private persistent variable constant

\<min\_value> : The minimum permissible value

\<max\_value> : The maximum permissible value

\<default\_value> : The default value to return should the retrieved value be less then the min\_value or greater than the max\_value

Returns

The stored value or the default value if the stored one is out of range

***

### set\_pvar

set\_pvar stores the specified value into a persistent variable. As GPC supports treating an int as a boolean value, the get\_val command can be used to see if a controller entry simply has a value.

Code-Snippet

```
int a, b, c;

init {
    a = get_pvar(SPVAR_1, 0, 10, 5);
    b = get_pvar(SPVAR_2, 20, 40, 30);
    c = get_pvar(SPVAR_3, -30, 400, 100);
}

main {
    if(event_press(XB1_VIEW)){
        set_pvar(SPVAR_1, a);
        set_pvar(SPVAR_2, b);
        set_pvar(SPVAR_3, c);
    }
}
```

Syntax

set\_pvar ( \<pvar\_constant> , \<value> );

Parameters

\<pvar\_constant> : A global or private persistent variable constant.

\<value> : A value to be stored

Returns

None


---

# 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/constants/persistent-memory.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.
