Define game object of factory in script

Is this possible? It does not look like it. I don’t want to create a different factory for every game object. Am I missing something? What is the reason for associating a single game project to a single factory? A runtime loading issue?

How about a kind of factory that you define a folder and it can create anything inside of it, and loading is handled based on that?

msg.post("#factory", "create", { position = some_position, rotation = some_rotation }, "/main/gameobjects/chest.go")

Yes, you have to have one factory per game object. At compile time we build a tree of everything used in the project and only include those files. That’s why you have to specify a specific game object. Depending on your game it can be a lot or only a few game objects.

At least for some things I would consider using a generic game object and then passing in properties when creating the game object to specify exactly what type of look and behaviour I want. Example:

Instead of having a rifle.go, machinegun.go, pistol.go I’d probably create a rangedweapon.go and pass in different properties to set the sprite, the type of bullet it fires, rate of fire, damage etc

Your example had a chest.go. Perhaps that could be a something as generic as container.go (chest, bag, pile, coffin etc)?

3 Likes

Thank you for explaining. Yes, some things can be generic. I am thinking more like designer objects that can’t easily be swapped and are used dynamically based on exported level data of some tool. Defold seems to be based around optimizing preset scenes and not dynamic content.

It may still be useful to have a way to select a folder and auto populate factories before compile time based on the game objects in that folder.

1 Like

A first step could be to have multiple game object prototypes (files) inside of a factory. You would then need to specify which one to spawn of course. Another thing to remember is that since the data files are text and the format is quite simple, you could quite easily generate a go-file with a factory for each go-file found in some directory. In general we like when things are explicit though. :slight_smile:

3 Likes