0 votes

I am trying to make a dictionary to be used as the directory architecture for a fake computer. I would just like to know if there is a way to go through multiple keys of a dictionary with one .get() statement, this is because I would like to have a multilayered structure and I want to do this in the most efficient way possible. What I am asking is would it be possible to do something like this

dictionary.get("key1/key2")

instead of doing

dictionary.get("key1").get("key2")

To restate the question is there a way to go through multiple keys of a dictionary using only one .get() statement?

Godot version 3.4.1
in Engine by (72 points)

1 Answer

+1 vote

You don't need any get() at all, just sraight formward reference the keys like this :
dictionary["key1"]["key2"]

by (5,132 points)

yes, but I was asking if I could do that in only a pair of brackets. I'm going to assume that there is no way to do that, thank you for your help.

I tried to use Nodepath to get to nested dictionaries, but it really doesn't seem to work. Maybe You could dig in deeper into property pathing, maybe it is possible in the end..

You can also always use nodes parenting systems as fake dictionary, this way You will be able to get() all kind of data within one pair of brackets. What I mean is : branched and complicated tree of parent-child relationship of Node, who has their data stored in meta. This way You can succesfully use property pathing get(Node1/Node2/Node3:meta)

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 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 webmaster@godotengine.org with your username.