Dictionary question

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rogerdv

Can somebody explain me how does the dictionary type works? My recent experiences are with Unity/C# dictionaries, and I would like to know the differences with GDScript dictionaries, because I have the impression that they are more like structs and not a key,value pair.

:bust_in_silhouette: Reply From: njamster

What caused your impression? The documentation for dictionary starts by stating: “Associative container which contains values referenced by unique keys”. It also includes gdscript-examples for everything (I would consider) important.

Because I couldnt find any example about how to iterate it. Also, a C#/C++ dictionary uses keys of a single type, like string, value_type. I see that GDScript can have keys of different types.

rogerdv | 2020-02-03 15:13

You can iterate through a dictionary’s keys or values by pulling them as an array, then running a for loop on them. For example:

for key in dict.keys():

or

for value in dict.values()

denxi | 2020-02-03 15:19