Apologies: awful title (mb) no idea what to name this, also I probably mix up a few OOP terms below, please correct me so I can edit them.
I am trying to go for an OOP structure similar to the Instance class, where you do Instance.new(ClassName), and it returns the object.
My example code looks like this:
local Test = {} -- Think of this as the "Instance" class
function Test.new(ClassName)
-- The children of the "Test" module are more modules holding the individual
-- objects I wish to index
return require(script[ClassName]).new()
end
return Test
local object1 = {} -- Example object
object1.__index = class1
function object1.new()
return setmetatable({}, object1)
end
function object1:get()
print("Method works")
end
return object1
Then, I index it like so: (wild commentary)
local Test = require(ReplicatedStorage.Test)
local object1 = Test.new("object1")
This code functionally works, however when indexing the :get() method it wont autocomplete. This is inconsequential, however I want to fix it because its
- annoying
- unfancy
Jokes aside, if anyone has a fix please let me know. Thank you for reading.