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!

Answers

  • RossRoss Posts: 199Member
    edited February 9

    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 9 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

Sign In or Register to comment.