Cronus GPC Documentation
Cronus CommunityGPC LibraryGPC Guide
  • Welcome
  • Introduction
    • GPC Explained
    • What's New with Zen?
  • Basic Syntax
  • A Simple Tutorial
  • Style Guide
  • GPC Structure
  • Basic GPC Structure
  • Definitions
  • Data Section
  • Remapping
  • Variables
  • Init Section
  • Main Section
  • Combo Section
  • User Created Functions
  • GPC Programming Basics
  • Constants
    • Zen
      • OLED
      • ASCII Constants
      • PIO
    • Keyboard
      • Keyboard
    • Controller
      • Polar
      • LED
      • Rumble
      • PS3
      • PS4
      • XBox 360
      • Xbox One
      • Nintendo WII
      • Nintendo Switch
    • Racing Wheel
      • G29
      • G27
      • G25
      • DF
      • DF GT
      • DF Pro
    • Trace
    • Memory
    • Misc
  • Flow Control
  • Persistent Memory
  • Operator Types
  • Identifiers
  • Functions & Commands
    • Internal Functions
      • Bit Functions
      • Combo Functions
      • Math Functions
      • Device Functions
      • OLED Display Functions
    • Console Functions
      • Core Console Functions
    • Controller Functions
      • Core Controller Functions
      • Rumble Functions
      • LED Functions
    • Keyboard Functions
      • Core Keyboard Functions
  • GPC Examples
    • #1
Powered by GitBook
On this page
  • get_pvar
  • Syntax
  • Parameters
  • Returns
  • set_pvar

Was this helpful?

Persistent Memory

PreviousFlow ControlNextOperator Types

Last updated 5 years ago

Was this helpful?

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 called 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 160 persistent variables on the CronusMax Plus (16 Global Variables and 144 Private Variables)

There are a total of 528 persistent variables on the Cronus Zen (16 Global Variables and 512 Private Variable)

Persistent Variables, or PVAR, can be accessed and set from any slot. They are generally used to pass values between scripts. 16 constants have been created for use with the get and set commands for persistent variables, they are:

PVAR_1

PVAR_2

PVAR_3

PVAR_4

PVAR_5

PVAR_6

PVAR_7

PVAR_8

PVAR_9

PVAR_10

PVAR_11

PVAR_12

PVAR_13

PVAR_14

PVAR_15

PVAR_16

Slot Persistent Variables, or SPVAR, are private to a specific memory slot. Each of the memory slots has 16 private variables (64 for Cronus Zen), 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 variables 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

Returns the value stored within a persistent variable

✔️

✔️

Stores a value into a persistent variable

✔️

✔️

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.

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

get_pvar ( <pvar_constant>, <min_value>, <max_value>, default_value> );

<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

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. For example:

int a, b , c;
 
init {
    a = get_pvar(SPVAR_1,  0, 10,  5);
    b = get_pvar(SPVAR_2, 20, 40, 30);
    c = get_pvar(PVAR_1, -30,400,100);
}
 
main {
 
    if(event_press(XB1_VIEW)){
        set_pvar(SPVAR_1, a);
        set_pvar(SPVAR_2, b);
        set_pvar(PVAR_1,  c);
    }
 
}

set_pvar ( <pvar_constant> , <value>);

<pvar_constant> : A global or private persistent variable constant. <value> : A value to be stored

None

Syntax

Parameters

Returns

Syntax

Parameters

Returns

🔴
⚪
🔵
🔴
⚪
🔵
get_pvar
set_pvar