Self calls don't work in custom functions (SOLVED)

What factory.create returns is not a reference, it is just the hashed ID of the new object. Basically just its name. You can’t use that as self. Are you used to using another game engine? With Defold you generally don’t call functions on game objects. If you want to communicate between objects you use message passing. Or, if you just need to transfer data you can use go.get and go.set with script properties, though the data types you can use with script properties are limited. Another option is to use a lua module with a lookup table or whatever (you can use a hashed ID as a table key for example).

There was another thread here recently about setting and getting stuff from factory-created objects.

Also, it’s generally a bad idea to define global functions (any custom function you define without the local keyword is global). It’s better to put things like that in a module. It’s way too easy to forget that you defined that name globally and cause yourself all sorts of weird bugs and headaches. A bit more about that in this thread.

1 Like