Godot-docs: Navigating through a complex dictionary is not mentioned on the docs or not clear.

Created on 12 Apr 2020  路  1Comment  路  Source: godotengine/godot-docs

So I am new to storage systems, and when parsing a complex json file I don't know how to go to a key inside of another key in a dictionary. I looked in these pages and didn't found it, searched on the q&a and few videotutorials and I'm not able to find how to do so.
Adding the explanation would be very helpful. Thanks.

https://docs.godotengine.org/en/latest/classes/class_dictionary.html#dictionary &
https://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_basics.html#dictionary

enhancement

Most helpful comment

func _ready():
    var dict = {
        "foo": {
            "bar": {
                "baz": true,
            },
        },
    }

    # Static string access (use this if you don't need dynamic access, it's easier to read and write):
    print(dict.foo.bar.baz) # Prints "True"

    # Dynamic access (use this if the key you're indexing with is dynamic):
    print(dict["foo"]["bar"]["baz"]) # Prints "True"

You can mix and match indexing styles together.

>All comments

func _ready():
    var dict = {
        "foo": {
            "bar": {
                "baz": true,
            },
        },
    }

    # Static string access (use this if you don't need dynamic access, it's easier to read and write):
    print(dict.foo.bar.baz) # Prints "True"

    # Dynamic access (use this if the key you're indexing with is dynamic):
    print(dict["foo"]["bar"]["baz"]) # Prints "True"

You can mix and match indexing styles together.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

golddotasksquestions picture golddotasksquestions  路  3Comments

jcs224 picture jcs224  路  3Comments

eon-s picture eon-s  路  5Comments

Gfurst picture Gfurst  路  3Comments

clayjohn picture clayjohn  路  4Comments