Local variable

From Dragon Age Toolset Wiki
Jump to: navigation, search

Local variables are persistent variables that are associated with in-game objects. They are not the same as the temporary variables you can create in a script; local variables retain their values even when no scripts are using them, and are shared across any scripts that choose to access them.

Functions that work

Local variables are set using the SetLocal* functions and read using the GetLocal* functions. There are a number of SetLocal* functions in the game engine. The five that are of use to you (that Programming fully supports) are:

These functions work and have been through the fire of QA for many months. They are solid and work well.

Functions that don't work

There are a number of other functions that happen to exist such as:

These functions do *NOT* work the way that the first five do. The major issue with this second set of functions is that they are not saved/loaded via the save system. So, if a community member or designer wants to save information like this for use later, and someone saves/loads the game, that information is lost forever. Thus, using them outside of situations where you can guarantee no save/load occurs (i.e. during combat) is pretty much guaranteed to fail for some enduser. Furthermore, if you use these variable types in the var_ 2DAs, it will fail gloriously.

Don’t use these functions. They will in all likelihood be removed in a future patch.

Variable 2DAs

Local variables must be pre-defined in a variable 2DA before they can be read or set using these functions. The structure of a variable 2DA is as follows:

Column Type Description
ID int A number that uniquely identifies the entry (unless creating an M2DA override). ID numbers are listed from smallest to highest within a given file but do not need to be consecutive.
Label string The name of the variable.
Type string The type of the variable.
Default string The default value of the variable. Resources can have the string "NONE" to indicate an empty default.
IsPlot int Set this to 1 to indicate that a string variable is meant to contain the name of a plot resource. 0 otherwise.

Each different type of resource has a standard default variable 2DA, whose entries are described in the variable tables associated with their respective articles. You can create your own variable tables or extend existing ones with M2DAs if you need additional local variables for specific objects.

Dragon Age doesn't support the dynamic in-game allocation of new local variables.

Scope of local variables

If a resource isn't currently loaded, you can't reference its local variables.

Module variables are always available. So are plot flags.

Variables for an area, and objects within it, are only available for the current area list.

So, those variables should only be used for information that will never be needed in other areas.


An alternative to local variables can be found in the unlimited variable storage project[1]. With a single include file and a simple function call in your module script, you can have unlimited variable and array storage with no need to declare anything in a 2da.