dictionary class built-in
Collection of values of any type, stored under string keys
Each key is unique and can hold a value of a different type. Values are accessed with the index operator, e.g. dict["name"] = "Jazz";, or with dictionary::set() and dictionary::get(). Integers are always stored as int64 and floating-point numbers as double. Keys are kept in no particular order. Can be created from an initialization list, e.g. dictionary d = {{"a", 1}, {"b", 2.5}};.
Constructors
- dictionary()
- Creates an empty dictionary
Functions
- bool delete(const string&in key)
- Removes a key and its value
- void deleteAll() C++
- Removes all entries
- bool exists(const string&in key) const C++
- Returns
trueif the key is in the dictionary - bool get(const string&in key, ?&out value) const
- Retrieves the value of a key
- bool get(const string&in key, int64&out value) const
- Retrieves the value of a key as an integer
- bool get(const string&in key, double&out value) const
- Retrieves the value of a key as a floating-point number
- array<string>@ getKeys() const
- Returns all keys
- uint getSize() const C++
- Returns the number of entries
- bool isEmpty() const C++
- Returns
trueif the dictionary has no entries - void set(const string&in key, const ?&in value)
- Stores a value of any type under a key
- void set(const string&in key, const int64&in value)
- Stores an integer under a key
- void set(const string&in key, const double&in value)
- Stores a floating-point number under a key
Operators
- dictionary& opAssign(const dictionary&in other) =
- Replaces the content with the entries of another dictionary
- dictionaryValue& opIndex(const string&in key) []
- Accesses the value of a key
- const dictionaryValue& opIndex(const string&in key) const []
- Reads the value of a key from a read-only dictionary
Constructor documentation
dictionary:: dictionary()
Creates an empty dictionary
Each item of the list is a pair of a key and a value, e.g. {{"lives", 3}, {"name", "Spaz"}}.
Function documentation
bool dictionary:: get(const string&in key,
?&out value) const
Retrieves the value of a key
| Returns | true if the key exists and its value could be converted to the type of the variable |
|---|
Takes the key and a variable that receives the value. A stored number, boolean or enum can be read as int64, double, bool or an enum, objects must match the stored type. The variable is left unchanged if it fails.
array<string>@ dictionary:: getKeys() const
Returns all keys
| Returns | New array of the keys |
|---|
The keys are in no particular order, sort the array with array::sortAsc() if needed.
Operator documentation
dictionary& dictionary:: opAssign(const dictionary&in other) =
Replaces the content with the entries of another dictionary
Stored objects are copied, stored handles keep referring to the same objects.
dictionaryValue& dictionary:: opIndex(const string&in key) []
Accesses the value of a key
If the key doesn't exist yet, it's added with an empty value, so this can be used for assignment.
const dictionaryValue& dictionary:: opIndex(const string&in key) const []
Reads the value of a key from a read-only dictionary
A key that doesn't exist raises a script exception.