Hello!
I am currently working on a data system for a currently solo project.
I tried a few different styles, but after a few days I ended up with object style system.
(Currently) The code works as intended (I am fairly new at this so that is a miracle), but I just have a feeling like something is off with the way I implemented classes
----VARS----
--Modules
local typeModule = require(script.Type)
local appModule = require(script.Appearance)
local module = {
["Apple"] = function()
return {
Name = "Apple"; -- Name of the object
ClassName = "Fruit"; -- Name of the class
Parent = nil; --Parent of the object
Type = typeModule.TestType; --Used to determine object type (project spcific)
Appearance = appModule.TestApp -- Used to determine the object appearance (project --specific)
}
end,
}
----END_VARS----
return module
In this case, I return a table using a function assigned to the class name using this function
function gameInstance.New(className : string)--Attempts to create and return an object from the --provided class name
if not className or typeof(className) ~= "string" then error("Expected class name string got " .. typeof(className)) end
--Check if class exists
local class = classData[className]
if not class then error("Unable to create Game Instance of class " .. className) end
--Call class as a function
return class()
end
If you have any tips for better implementation please share.
Or if this is fine let me know I guess.
Sorry if the post is a mess. This is my first one