I propose 2 new functions.
DictionaryAdd
If the dictionary item exists, it is overwritten.
<function name="DictionaryAdd" parameters="dict, key, val">
if (dict = null) {
Log ("DictionaryAdd ERROR: Dictionary does not exist!")
return (false)
}
if (not DictionaryContains(dict,key)) {
dictionary add (dict, key, val)
}
else {
if (not DictionaryItem(dict,key) = val) {
dictionary remove (dict, key)
dictionary add (dict, key, val)
}
}
</function>
DictionaryRemove
Checks for the dictionary item's existence before removing it.
<function name="DictionaryRemove" parameters="dict, key">
if (dict = null) {
Log ("DictionaryAdd ERROR: Dictionary does not exist!")
return (false)
}
if (DictionaryContains(dict,key)) {
dictionary remove (dict, key)
}
</function>
In both scripts, if the dictionary parameter is null, an entry is added to the log (rather than throwing an error *), and the script exits.