This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Ask value from key in dictionary

bobokoxbobokox Posts: 5Member

Hey. I have a problem to get the value of a key entry in my dictionary using a for loop to check all entrys.

onready var items = get_tree().get_nodes_in_group("item") var vitem = {} func _ready(): set_fixed_process(true) func _fixed_process(delta): for i in items: var name = i.get_name() vitem = {name:1} for i in vitem: if i.value() == 1: #################################### print(i) var pic = get_node("items"+str(i)) pic.set_pos(Vector2(0,0))
the line with the quotes doesn't work. i also tried vitem.i, but godot searches for a entry named "i" in the dictionary. does anybody know how to solve this?

thank you very much!

Best Answer

Answers

  • RossRoss Posts: 199Member
    edited February 2017

    You access values in a dictionary with brackets. dictionary[key]. If the key is a string without spaces you can also use the dot notation: dictionary.key. You should read the documentation. You can also look up Python documentation (or basically any other language with dictionaries afaik) for more details on when each method can be used.

    What is this value() function you're using? I couldn't find it in the docs, is that your own function? I don't know what your code is supposed to do or I would rewrite it for you.

  • bobokoxbobokox Posts: 5Member
    edited February 2017 Accepted Answer

    thank you.
    i think my explanation was not good. anyway, already got an answer in qa.
    https://godotengine.org/qa/12240/get-value-of-key-from-dictionary

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.