Godot Version
4.4
Question
I have a dictionary with keys and values, keys are the names of variables, and I want to compare the key with the name of the variable and set the value, but I do not know how to access this variable.
4.4
I have a dictionary with keys and values, keys are the names of variables, and I want to compare the key with the name of the variable and set the value, but I do not know how to access this variable.
You may have to post more code than that, I’m not sure I understand the question but it seems like you want to iterate over a dictionaries keys and assign a variable based on a dictionary, the code sample implies it only affects variables that do exist and silently ignores any missing variables.
Maybe set
is what you are looking for as it takes a string and assigns a matching variable.
func apply_dictionary(dict: Dictionary[String, Variant]) -> void:
for key in dict.keys():
if key in self:
self.set(key, dict[key])
I decided not to use variables and use dictionaries instead.