Loop through dictionary using keys

Godot Version

4.2

Question

How to iterate over the keys of a dictionary to get the values?

	for obj in get_node("level").get_children():
		obj_list[obj.name] = {
			"position":Vector2(obj.global_position.x,obj.global_position.y)
		}
		
    for item in obj_list:
		print(item["position"])

for key in dict.keys():
	print(dict[key])

What if i need to print the value from specific key?

use if then
then break if found specific key

though, you can just dict[specific_key_value], no?

No…based on the code that i posted , it gives the following error:

“Invalid get index ‘position’ (on base: ‘Dictionary’).”

Got it

    for item in obj_list:
		print(obj_list[item]["position"])

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.