Recently, I have developed an OOP-styled hierarchical finite state machine (a tree-behavioural AI) and the way I reference the creation of a new AI is using an OOP-method.
If I were to for example declare a new table in the same script as I run the method and use insert models inside this table as values everything will work fine. representation:
local class = {}
local module = require(module)
table.insert(class, #class+1, module.new(object))
for _, v in pairs(class) do
v:Method()
end
This code will run perfectly! In contrast to declaring a table inside another module
--module
local moduleTable = {}
return moduleTable
--script
local moduleTable = require(moduleTable)
local module = require(module)
table.insert(moduleTable, #moduleTable+1, module.new(object))
for _, v in pairs(moduleTable) do
v:Method()
end
This will run into the error of method not being a valid member of object (… or v if you prefer that).