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 true if 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 true if 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::delete(const string&in key)

Removes a key and its value

Returns true if the key existed

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.

bool dictionary::get(const string&in key, int64&out value) const

Retrieves the value of a key as an integer

Returns true if the key exists and holds a numeric value

Takes the key and a variable that receives the value. A stored floating-point number is truncated.

bool dictionary::get(const string&in key, double&out value) const

Retrieves the value of a key as a floating-point number

Returns true if the key exists and holds a numeric value

Takes the key and a variable that receives the value.

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.

void dictionary::set(const string&in key, const ?&in value)

Stores a value of any type under a key

Takes the key and the value. Replaces any previous value of the key. Objects are stored as copies, pass a handle (e.g. @obj) to store a reference to the object instead.

void dictionary::set(const string&in key, const int64&in value)

Stores an integer under a key

Takes the key and the value. Replaces any previous value of the key.

void dictionary::set(const string&in key, const double&in value)

Stores a floating-point number under a key

Takes the key and the value. Replaces any previous value of the key.

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.