Storing built-in values
Storing in the array
ArrayList
serves the role of the regular array and storing built-in value data
inside it is simple:
local ArrayList data;
data = _.collections.EmptyArrayList();
// Add as the last element
data.AddFloat(-2.5);
// Set at a particular index (length will be auto-adjusted)
data.Set(2, "just a string");
Log("data[0] =" @ data.GetFloat(0)); // data[0] = -2.5
Log("data[1] =" @ data.IsNone(1)); // data[1] = true
Log("data[2] =" @ data.GetString(2)); // data[2] = just a string
Getting string
as a Text
By default Acedia's collections use Text
to store string
s, so we can also
get their values as Text
:
local Text textInstance;
local ArrayList data;
data = _.collections.EmptyArrayList();
data.SetString(0, "Hello, world!");
textInstance = data.GetText(0);
Log("data[0] =" @ textInstance.ToString());
// Same as any object returned by a function, `textInstance` must be released
textInstance.FreeSelf();
Storing values by keys
For storing values using keys instead of numeric indices, the Acedia's way is to
use HashTable
:
local HashTable data;
data = _.collections.EmptyHashTable();
data.SetBool(P("Deal damage?"), true);
data.SetInt(P("Damage amount"), 9001);
Log("Deal damage?" @ data.GetFloat(P("Deal damage?"))); // Deal damage? true
Log("Damage amount:" @ data.IsNone(1)); // Damage amount: 9001