Array[String] typing question

Godot Version



What is the best way to use typing for this case and why?
(I know that dictionary typing won’t be coming soon, but I’m already getting ready)

var FUNCS: Dictionary = { #Dictionary[String, Callable]
	func1 = func() -> void: pass,
	func2 = func() -> void: pass,
func update_funcs(func_name := '') -> void:


	for v: String in ([func_name] if !func_name.is_empty() else FUNCS):

B) (I think it’s slower because of the keys() function)

	var list: Array[String] = [func_name] if !func_name.is_empty() else FUNCS.keys() as Array[String]
	for v: String in list:

Or is it just better to create a function for further code processing and do so?
(But want to know the explanation of the above)

if !func_name.is_empty():
	for v: String in FUNCS:
  • A
  • B
  • с
0 voters

key from dictionary should be quicker than array finding and match the string
also you can actually test it yourself by counting the difference of Time.get_ticks_msec() before and after calling the the key you wanted

also have a read on this:


I mean if the list of funcs is not changing at runtime, you could also have an enumeration to name the array indices. But if it’s dynamic then a dictionary would probably be better.


Oh. No, it doesn’t change