Godot读了嵌套词典
我正在尝试在Nest词典中访问项目。硬编码是很好的dict [string_1] [string_1a],但是当用户选择UI中的项目并向下钻探时,我不确定如何“关注”它们。我有一个小lendedit,可以显示诸如String_1/String_1之类的路径(类似于计算机显示文件夹的方式)。但是,如果我想创建一个新项目,例如[string_1] [string_1b],我不确定该怎么做。我能够用路径[string_1] [string_1b]打印字符串,但是我不知道如何将其实际添加到字典中,因为我无法做str2var(我知道),我可以t只需传递字符串_1b,就必须在String_1内部。
func update_path(object, full_path):
var new_path = ""
full_path.insert(0, object.get_text(0))
new_path = object.get_parent()
if new_path != null:
update_path(new_path, full_path)
else:
pathEdit.text = ""
# for some stupid reason I can't remove 0, it throws an error
for item in full_path:
if item != "":
pathEdit.text += item + "/"
print("saving subcategory")
print(pathEdit.text)
var save_path= pathEdit.text.split("/")
print(save_path)
var dumb_string = "Globals.notebook_data"
for path in save_path:
if path != "":
print(path)
#print(Globals.notebook_data[path])
#print(Globals.notebook_data[save_path])
#print("Globals.notebook_data"+ )
dumb_string += "[" + path + "]"
print(dumb_string)
print(str2var(dumb_string))
字符串是正确的路径,我只是不知道如何“访问”它。我正在考虑循环浏览数组,但是我不确定如何处理它,如果我只是访问该级别,它就不会使字典保持整体。
I am trying access items in a nest dictionary. Hard coding it is fine dict[string_1][string_1a], but when user is selecting items in the UI and they drill down, I am not sure how to "follow" them. I have a little LineEdit that shows the path such as string_1/string_1 (similar to how computers show folders). However, if I want to create a new item such as [string_1][string_1b], I am not sure how to do that. I am able to print the string with the path [string_1][string_1b], but I don't know how to actually add that back into the dictionary as I can't do str2var (that I am aware of), and I can't simply pass string_1b as it has to be inside string_1.
func update_path(object, full_path):
var new_path = ""
full_path.insert(0, object.get_text(0))
new_path = object.get_parent()
if new_path != null:
update_path(new_path, full_path)
else:
pathEdit.text = ""
# for some stupid reason I can't remove 0, it throws an error
for item in full_path:
if item != "":
pathEdit.text += item + "/"
print("saving subcategory")
print(pathEdit.text)
var save_path= pathEdit.text.split("/")
print(save_path)
var dumb_string = "Globals.notebook_data"
for path in save_path:
if path != "":
print(path)
#print(Globals.notebook_data[path])
#print(Globals.notebook_data[save_path])
#print("Globals.notebook_data"+ )
dumb_string += "[" + path + "]"
print(dumb_string)
print(str2var(dumb_string))
The string is the correct path, I just simply don't know how to "access" it. I was thinking of looping through the array, but I am not sure how to tack it on, and if I simply access just that level it doesn't keep the dictionary whole.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到答案,需要递归保存。
https://godotengengine.orgg/qa/ 81247/by-a-dictionary-by-titerrating-on-it-its-keys
Found an answer, needed to save it recursively.
https://godotengine.org/qa/81247/update-a-dictionary-by-iterating-on-its-keys