This is just a general thread to collect thoughts on how to make Defold games moddable. I am putting in some legwork to try and outline the fundamentals as I understand them, but I would love to hear your thoughts on anything I might have missed or misunderstood. Certainly by the end of the posts I have more questions than answers.
What do you need to make a game moddable? Well, you need tools and editors for people to create content - and I am going to ignore that for now… What I am more curious about at this point, is how to make Defold incorporate and respond to the content generated by users.
The first hurdle, then, is how to make Defold see the user generated content. Referring to this thread, I find that Lua has an I/O library which should be helpful in loading files. Lua doesn’t have a concept of a file system with folders, however. A dirty fix would be to load a specific index file with paths to all other required content, but a better solution might be Defold-LFS - a Defold native extension written by @britzl for the LuaFileSystem library (“a portable way to access the underlying directory structure and file attributes”).
So if we can load files, what kinds of files and what do we do with them?
The simplest, yet very powerful, would be loading some sort of data (narrative, character stats, enemy characteristics - you name it). You could load a JSON file and parse it with the in-built Defold JSON API or the CJSON extension (not sure what the relative benefits are).
What about images? A good answer here appears to be ImageLoader written by @sergey.lerg, which allows loading of images external to the game. This is fine for static images, but I am not aware of how you would go about dynamically creating (or even replacing existing) atlas animations.
Getting even more complicated: Can we load and execute external scripts? Do we even want to - if it’s potentially a security risk? This post certainly makes it seem possible to do so with bundled files, perhaps you can do the same with external files using the file system solutions mentioned above?
What about sounds and music? I’m not sure. This is perhaps more related to a broader question touched upon in the secion on images: Are there any of Defold’s components that could be loaded externally? Modified by externally loaded content? Can we change a default three-frame animation of a running man to a five-frame animation of a horse?