Topic was automatically imported from the old Question2Answer platform.
Asked By
vonflyhighace2
Old Version
Published before Godot 3 was released.
I can’t seem to reproduce the same functionality that python has when it comes to dictionaries. I have a function inside a dictionary func foo(): but when I try to access it using standard python syntax eg."myDict['foo']() theirs automatically a error with the IDE saying that it needs an end of statement after the expression. What Gives? I’m still a newb after all I guess
The problem is that functions are not first-class objects. This means that objects/classes can have methods, but those methods are completely useless unless you have both the object and the method. Also, the other point is that you can’t just mixin a function into an existing object, without changing its class.
What you might be trying to do is using Dictionary as a class for everything, JavaScript-style. In GDScript, this is done by making a new class, either via a new .gd file, or via the class keyword. You can find more information about this on the GDScript article in the docs or in this other answer I gave