✓ Accepted answer
What you are trying to do is called circular dependency, this is bad bad, you should improve your module structure to avoid it, but it might be difficult, and if so, what you asked for can be done by using third module which is going to store the data that should be shared across the modules, and both Vector and Angles are going to require it without having to require each other.
The only problem is that requiring other modules before the module hit return is unsafe since we don't yet know what content will current module have, in frameworks people create function for each module (often called init), then they preload all modules into a table and then after all modules are ready they call the function in every module, when this function is executed, the module knows for sure that all of the other modules are ready and can start relying on them or execute some code.
However, for a simpler version you can use custom require function which will avoid circular dependency like this:
Module A requires module B
Custom require creates empty table for module A inside of some table
Module B requires module A
Custom require creates empty table for module B inside the same table
Custom require sees that module A has a table inside of the table meaning it has already been required, it returns that table without requiring the module again, for now the table is empty.
Module B hits return and custom require replaces the empty table it previously created into return value of module B
Module A hits return and custom require replaces the empty table it previously created into return value of module A
I made it look complicated, you better see the code, it's few lines, this logic has 1 drawback and that's that you can't use contents of the module you circularly require outside of a function.
req (ModuleScript)
local required_modules = {}
local function req(module)
local existing = required_modules[module]
if existing ~= nil then
return existing
end
required_modules[module] = {}
local new = require(module)
for key, value in pairs(new) do
required_modules[module][key] = value
end
return required_modules[module]
end
return req
Angle
local req = require(path.to.req)
local VectorGlobals = req(script.Parent.Vector)
function globals.Angle()
end
return globals
Same logic with Vector module, you can see it's actually not that bad, however, avoiding circular dependency is going to make your structure far better. In your case you could merge your modules into single one since they do practically the same.
1 comment
You can do anything in roblox, also im a bit confused, what r u trying to do?