0 votes

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.

in Engine by (185 points)

1 Answer

0 votes
Best answer

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.

by (10,628 points)
selected by

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.

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()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.