Skip to content

Dictionary functions

Functions for manipulating dictionaries. For a discussion on how to use dictionaries, see here.

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.

See Using Dictionaries

DictionaryContains (dictionary, string key)

hard-coded

Returns a boolean - true if the dictionary contains an element with the specified key.

See Using Dictionaries

DictionaryCount (dictionary)

hard-coded

Returns an int - the number of items in the dictionary.

See Using Dictionaries

DictionaryItem (dictionary, string key)

hard-coded

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.

See Using Dictionaries

DictionaryRemove (dictionary, string key)

Removes from the dictionary the element with the specified key. If there is no such key, it does nothing.

See Using Dictionaries

NewDictionary ()

hard-coded

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 ()

hard-coded

Returns an empty objectdictionary.

NewScriptDictionary ()

hard-coded

Returns an empty scriptdictionary.

NewStringDictionary ()

hard-coded

Returns an empty stringdictionary.

ObjectDictionaryItem (dictionary, string key)

hard-coded

Returns the object specified by the dictionary key.

You can use the DictionaryItem function if you don’t know the type of the dictionary.

See Using Dictionaries

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 (scriptdictionary, string key)

hard-coded

Returns the script specified by the dictionary key.

You can use the DictionaryItem function if you don’t know the type of the dictionary.

See Using Dictionaries

StringDictionaryItem (stringdictionary, string key)

hard-coded

Returns the string specified by the dictionary key.

You can use the DictionaryItem function if you don’t know the type of the dictionary.

See Using Dictionaries