![]() |
AngelScript
|
The dictionary stores key-value pairs, where the key is a string, and the value can be of any type. Key-value pairs can be added or removed dynamically, making the dictionary a good general purpose container object.
obj object; obj @handle;
// Initialize with a list dictionary dict = {{'one', 1}, {'object', object}, {'handle', @handle}};
// Examine and access the values through get or set methods ... if( dict.exists('one') ) { // get returns true if the stored type is compatible with the requested type bool isValid = dict.get('handle', @handle); if( isValid ) { dict.delete('object'); dict.set('value', 1); } }
// ... or through index operators int val = int(dict['value']); dict['value'] = val + 1; @handle = cast<obj>(dict['handle']); if( handle is null ) @dict['handle'] = object;
// Delete everything with a single call dict.deleteAll();
The dictionary object is a reference type, so it's possible to use handles to the dictionary object when passing it around to avoid costly copies.
The assignment operator performs a shallow copy of the content.
The index operator takes a string for the key, and returns a reference to the value. If the key/value pair doesn't exist, it will be inserted with a null value.