Dictionaries Godot GDScript Tutorial Ep 12 Godot Tutorials
Dictionaries Godot GDScript Tutorial Ep 12 Godot Tutorials
Learning Materials
Article Resource
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-12 Page 1 of 4
Dictionaries | Godot GDScript Tutorial | Ep 12 | Godot Tutorials 5/8/23 4:41 PM
Dictionaries
Dictionaries, also referred to as a key-value store, are associative containers that contain values referenced by keys.
In the code above, the key name, while the value is "John"
You are also able to use other datatypees besides strings as keys:
Accessing Dictionaries
# Create Dictionaries
var simpleDictionary = {"name": "John"}
var integerDictionary = {1: "Jane"}
var floatDictionary = {2.13: "Josh"}
var booleanDictionary = {true: "Sarah"}
# Retrieve values
var getJohn = simpleDictionary["name"] # "John"
var getJane = integerDictionary[1] # "Jane"
var getJosh = floatDictionary[2.13] # "Josh"
var getJohn = booleanDictionary[true] # "Sarah"
# One way
simpleDictionary["name"] = "Jane"
# Another way
simpleDictionary.name = "Jane Doe"
simpleDictionary.age = 0
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-12 Page 2 of 4
Dictionaries | Godot GDScript Tutorial | Ep 12 | Godot Tutorials 5/8/23 4:41 PM
if(simpleDictionary == sameDictionary):
# Block of code never runs
To get the desired results when coparing dictionaries, use the hash method:
if(simpleDictionary.hash() == sameDictionary.hash()):
# Block of code runs
simpleDictionary.erase("name")
Dictionaries | Godot GDScript Tutorial | Ep 12 video & article by Godot Tutorials is licensed under a Creative Commons Attribution-
ShareAlike 4.0 International License .
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-12 Page 3 of 4
Dictionaries | Godot GDScript Tutorial | Ep 12 | Godot Tutorials 5/8/23 4:41 PM
Subscribe to my Newsletter
Join our newsletter and get news in your inbox! We hate spam too, you
won't get any from me :)
Email... SUBSCRIBE
GODOT TUTORIALS
WEBSITE RESOURCES LEGAL OTHER
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-12 Page 4 of 4