data_get_var - ryzom/ryzomcore GitHub Wiki
title: Data Get Var description: Retrieve a persistent script data variable published: true date: 2026-03-14T00:00:00.000Z tags: editor: markdown dateCreated: 2023-03-16T22:22:02.337Z
The dataGetVar native AI script function retrieves the value of a persistent script data variable. These variables survive AI service restarts and are stored in a binary PDR file on disk.
(value: s)dataGetVar(name: s) // returns string
(value: f)dataGetVar(name: s) // returns float-
name (string): The variable identifier in the format
"filename:variablename". The colon separates the file group from the variable name within that group.
- value (string or float): The stored value. Returns an empty string or 0 if the variable doesn't exist.
Variables are organized into named groups (the "file" part) and individual variables within each group. This creates a two-level namespace:
"GroupName:VariableName"
For example, "Fyros:PatrolCount" stores a variable called PatrolCount in the Fyros group. All variables in the same group are stored together internally.
This is a naming convention only — the "file" name doesn't correspond to an actual file on disk. All groups are saved together in a single PDR file per AI service instance.
Variables are automatically persistent:
- Stored in
ai_script_data/<ais_name>_pdr.binin the shard save directory - Saved automatically by the Backup Service when changes are detected
- Loaded on AI service startup
- Survive service restarts
See dataSave for details on the persistence mechanism.
// Read a string variable
($state)dataGetVar("Fyros:Patrol1State");
if ($state == "active") {
// patrol is active
}// Read a numeric variable
(count)dataGetVar("Fyros:PatrolCount");
count = count + 1;
()dataSetVar("Fyros:PatrolCount", count);- If the variable doesn't exist, a warning is logged and the return value is an empty string (for the string variant) or 0 (for the float variant).
- Variables are scoped to the AI service instance, not to a specific group or manager. Any group in the same AI instance can read and write the same variables.
- dataSetVar - Set a persistent variable
- dataSave - Save variables (no-op, persistence is automatic)
- setNelVar - Set a non-persistent runtime variable
Source: ryzom/server/src/ai_service/nf_static.cpp (dataGetVar_s_s, dataGetVar_s_f), ryzom/server/src/ai_service/ai_script_data_manager.cpp