7.4. Saving Variables Permanently

You can define variables for use in your Perl scripts. Since KildClient has a full-featured Perl interpreter, you can use all kinds of variables Perl supports (scalars, arrays, hashes, and even references to build complex data structures), and you use them just like you would in Perl.

However, when you close the World, the variables and their values are lost. However, it is often desirable to keep the values of variables across sessions, and KildClient has a mechanism for that.

A variable can be made permanent. All variables that are marked as permanent will be saved when you close the World, and will be reloaded from the saved values when the World is opened again later. This way, their values are saved across sessions.

To make a variable permanent, open the World Editor (see Chapter 4, Editing a World) and select the Variables section inside Automation.

There you will see a list of the variables that are set to be permanent:

Figure 7.1. Permanent Variables
Permanent Variables.

To add a variable, click the Add button. A window will open for you to enter the name of the variable.

To make one or more variables temporary again, select them and press Delete. They will be removed from the list.

Finally, if you mispell the name of a variable, select it and press Edit to correct it.

You can also change the order of the variables with the Up and Down buttons. This is usefor for grouping similar variables together, but does not otherwise affect the saving of the variables.

7.4.1. Permanent Variables in the Command Line

It is possible to make a variable permanent from the command line. To do that, use the $world->makepermanent function, passing the name of the variable as the argument. Note that since you must pass the name of the variable, you must use quotes, and preferably single quotes so that the variable does not get interpolated. For example, to make the variable $kill_count permanent, run $world->makepermanent('$kill_count'). Now when you close the World, the value of $kill_count will be saved, and when you reopen it later, the value will be restored.

It is possible to make more than one variable permanent at one time, just pass all their names as arguments to $world->makepermanent.

If you want a variable to stop being permanent (that is, to become temporary again), use the $world->maketemporary function. It is called just like makepermanent, and has the opposite effect.

To get a list of the variables that are currently permanent, use the function $world->listpermanent. This function has no arguments, and prints all the names of the variables that are permanent.