Dictionaries
The puzzles from this category allow you to create and operate on dictionary values.
Contents
Introduction
Dictionaries are very useful when you need to store, transfer, and retrieve various data in the same entity. Particularly, a dictionary is useful for storing multiple parameters and for passing them in bulk to Puzzles (such as raycast or collision info), JavaScript, or over network.
For example you might define a car with the following dictionary:
... which internally looks like this:
{
"available": true,
"brand": "Tesla",
"model": "Model S",
"range": 250,
"year": 2020
}
Inside the curly brackets are dictionary items. Each item has a key (e.g. "model") and a value ("Model S") associated with it. Keys are always defined as strings, but values can be of any type (strings, numbers, booleans, lists, other dictionaries, etc.) Also, contrary to lists, there is no particular sorting order applied to dictionary items, so you can add them in arbitrary order.
Puzzles Reference
create empty dict
Returns a dictionary containing no data records.
Internally in JavaScript, an empty dictionary is represented by an object without any properties, that is { }.
create dict with
Returns a dictionary with given keys and values.
Keys/values can be lists:
or multi-line texts, where each line represents a key or value:
dict set key
Sets the item to be associated with a specified key in a dictionary. The key must be a text, while the assigned value may be of any type (text, number, list, other dictionary, etc).
dict get key
Returns the item associated with a specified key in a dictionary.
get keys
Returns a list of all keys present in a dictionary.
dict check key
Checks if a specified key is present in a dictionary, and returns the Boolean-typed result true or false.
dict remove key
Removes the item associated with a specified key in a dictionary, and deletes the key itself.
is empty
Checks if a specified dictionary contains no keys, and returns the Boolean-typed result true or false.
See Also
- lists — if you need an ordered storage with indexed items.
- for each in dict — to iterate over dictionary items.
- send data — to send dictionaries over network.
Having Troubles with Puzzles?
Seek help on the forums!