Dictionary functions
Functions for manipulating dictionaries. For a discussion on how to use dictionaries, see here.
DictionaryAdd
Section titled “DictionaryAdd”DictionaryAdd (dictionary, string key, any type value)Adds to the dictionary an element with the specified key and value. If an element with that key already exists in the dictionary, that element will be removed first.
DictionaryContains
Section titled “DictionaryContains”DictionaryContains (dictionary, string key)Returns a boolean - true if the dictionary contains an element with the specified key.
DictionaryCount
Section titled “DictionaryCount”DictionaryCount (dictionary)Returns an int - the number of items in the dictionary.
DictionaryItem
Section titled “DictionaryItem”DictionaryItem (dictionary, string key)Retrieves the specified item from the dictionary. Returns a string or an object, depending on whether the dictionary is a stringdictionary or an objectdictionary.
Usually you will know the type of list that you’re passing in, so you should use the StringDictionaryItem, ObjectDictionaryItem or ScriptDictionaryItem functions instead.
DictionaryRemove
Section titled “DictionaryRemove”DictionaryRemove (dictionary, string key)Removes from the dictionary the element with the specified key. If there is no such key, it does nothing.
NewDictionary
Section titled “NewDictionary”NewDictionary ()Returns an empty dictionary. The dictionary can contain any type of data, or a mixture - for example, both objects and strings.
If the dictionary will only contain one type of data (as will usually be the case), you should use NewStringDictionary or NewObjectDictionary instead.
NewObjectDictionary
Section titled “NewObjectDictionary”NewObjectDictionary ()Returns an empty objectdictionary.
NewScriptDictionary
Section titled “NewScriptDictionary”NewScriptDictionary ()Returns an empty scriptdictionary.
NewStringDictionary
Section titled “NewStringDictionary”NewStringDictionary ()Returns an empty stringdictionary.
ObjectDictionaryItem
Section titled “ObjectDictionaryItem”ObjectDictionaryItem (dictionary, string key)Returns the object specified by the dictionary key.
You can use the DictionaryItem function if you don’t know the type of the dictionary.
QuickParams
Section titled “QuickParams”QuickParams (string key1, any type value1)QuickParams (string key1, any type value1, string key2, any type value2)QuickParams (string key1, any type value1, string key2, any type value2, string key3, any type value3)QuickParams offers a quick way to create a dictionary, and is especially useful for passing to a script (where local variables will be available with the key used as the name, and the value as the value). The key must therefore be a string, but the value can be of any type.
The function can take 2, 4 or 6 parameters to give a dictionary with 1, 2 or 3 entries.
d = QuickParams("obj", apple)d = QuickParams("obj", apple, "count", 45)d = QuickParams("obj", apple, "count", 45, "s", "Hmm, yummy")Now you can invoke a script, passing three parameters all in one line:
do (npc, "givefood", QuickParams("obj", apple, "count", 45, "s", "Hmm, yummy"))In this example, the “givefood” script attribute of the NPC is called. In the script, there will be three local variables available, obj, count and s.
ScriptDictionaryItem
Section titled “ScriptDictionaryItem”ScriptDictionaryItem (scriptdictionary, string key)Returns the script specified by the dictionary key.
You can use the DictionaryItem function if you don’t know the type of the dictionary.
StringDictionaryItem
Section titled “StringDictionaryItem”StringDictionaryItem (stringdictionary, string key)Returns the string specified by the dictionary key.
You can use the DictionaryItem function if you don’t know the type of the dictionary.