I’m creating a game heavily inspired by minecraft, and the following scripts are direct features from minecraft.
I currently have an issue with module circular dependency. I currently have 3 module scripts, inventory, dropped, and pickup.
Inventory → Dropped → Pickup → Inventory again
Inventory handles the inventory system and can also drop an item (think of selecting an item then right clicking outside your inventory in minecraft)
Dropped handles registering an item and animating it
Pickup is in charge of determining the distance of the player from each dropped object, if they’re close then they’ll pick it up (by adding to inventory)
I’m not experienced at module script hierarchy, are there any recommendations for designing this system, and should I adopt a certain hierarchy style I’m not aware of?
Currently, none of these scripts are classes. They consist of a initialization function (called from the local script) that activate input events. The rest of the module consists of a bunch of functions. Not sure if this is a good way to structure the code or if there is another standard practice.
you should not depend on another module that depends on the same module
module a needs b and b needs a is a bad way to design it. I’m certain you probably figured this out by now, but a band aid solution is to require it on a start function where its safe to call eachother
local ModuleA = nil
module.init = function()
end
module.start = function() -- // this is a safe space for circular dependencys
ModuleA = require(pathtomodulea)
end