1. How do persistent variables keep their value?
When you reboot after downloading a new program, the master loads the new program into memory before erasing the old one. The master searches through the two programs for matching persistent variables; i.e., a variable with the same variable name, source location (filename), and variable type. It then updates the new program with the persistent values from the old, and when it's finished, it deletes the old program from memory.
2. Why can't I use CLEAN DISK to reset the value of persistent variables?
CLEAN DISK does not clear the RAM memory. That's where the values are stored (with the rest of the running program).
3. What are some ways to reset the value of persistent variables?
- To clear all the values - change the name of the program, download, and reboot.
- To clear all the values - download a different program, reboot.
- To clear one value - change it's name; e.g., rename "nFlag" to "Flag".
- To clear one value - change it's type; e.g., instead of declaring "Flag" as INTEGER, declare it as LONG or CHAR.
- To set variables to a specific value only on the first download, use the code below:
DEFINE_VARIABLE
PERSISTENT INTEGER nVARS_SET
PERSISTENT INTEGER nSOME_VAR_1
PERSISTENT INTEGER nSOME_VAR_2
PERSISTENT INTEGER nSOME_VAR_3
PERSISTENT INTEGER nSOME_VAR_4
DEFINE_START
IF (!nVARS_SET)
{
ON[nVARS_SET]
nSOME_VAR_1 = 1
nSOME_VAR_2 = 2
nSOME_VAR_3 = 3
nSOME_VAR_4 = 4
}
If you want to reset the variables back to their defaults, use debug to set "nVARS_SET" to 0, then reboot.
4. Why don't persistent variables work in modules?
With modules there is the potential for a number of variables with the same name but located in different instances of a particular module. Since these duplicate variables all have the same name, source location (filename), and type - a fourth attribute would have to be determined. This has not yet been done.