I encountered the following problem:
I have a NPC class simple example:
local npc = {} local npc\_mt = { \_\_index = npc } -- metatable local worldHelper = require("classes.modules.worldhelper") function npc.new(\_name) -- constructor local pc = { name = \_name } return setmetatable( pc, npc\_mt ) end function npc:spawnNPC2() worldHelper.spawn("NPC2") end
And a worldHelper (spawner)
local t = {} local npcClass = require("classes.npc") t.spawnNPC = function(name) npcClass.new(name) end return t
As this is just a simple example it shows what I wanna do, I want the spawnable to access the worldHelper and spawn a new instance of the spawnable
But I get the following error when i do this: " loop or previous error loading module"
I know that it means it goes in an infinite loop requiring eachother, but is there any other way to achieve this?
I have a temp fix that requires the npc from my scene and puts it in an global var so the worldHelper can also access the npcClass without having to require it, but I dont like that solution