Alternative OOP structure for syntax autocompletion

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

  1. annoying
  2. unfancy

Jokes aside, if anyone has a fix please let me know. Thank you for reading.

This is most likely a limitation with Roblox’s code editor. I think it was only recently (last year or two) that they even supported autocomplete from Module Scripts to the scripts that require them.

1 Like

Unfortunately require currently only types for direct paths to modules.

What you can do is just put all your classes in one table and require it so you can do Classes.Object.new().

Thank you both, I will be doing this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.