I don't see any obvious way to set the type for variable in a for
loop.
For example, if I have an array of type Dictionary
, the following is not legal:
# not valid Godot syntax
for value:Dictionary in my_array:
# do_stuff expects a parameter of type Dictionary, so it's an error
do_stuff(dictionary_value)
I can cast the type on the variable when I use it:
# iterate through my_array
for value in my_array:
# do_stuff expects a Dictionary parameter, so perform explicit cast
do_stuff(Dictionary(value))
Or I can put it in another variable that declares the type:
# iterate through my_array, putting value in proxy
for value in my_array:
# put in a variable of type Dictionary for convenience
var dictionary_value:Dictionary = value_tmp
# can now call do_stuff without issue, because type is Dictionary
do_stuff(dictionary_value)
How expensive is theDictionary()
operation? If I do it multiple times, is it better to put it in an explicitly declared variable?