ObjectController is a module that allows developers to easily create custom classes that support inheritance
Example usage
local ObjectController = require(game.ReplicatedStorage.ObjectController)
local Object = ObjectController.Create("ClassName")
Object:SomeMethod()
Object.Value = 5
local AnotherObject = ObjectController.new("ClassName") -- .new() exists for consistency with Instance.new
Example class
local Class = {
Value = 0,
}
function Class.Init(self)
print("Initializing " .. self.Class .. ", setting value to 5!")
self:IncreaseValue(5)
print("Value is now " .. self.Value)
end
function Class:IncreaseValue(Amount)
print("Increasing value by " .. tostring(Amount))
self.Value = self.Value + Amount
return self.Value
end
return Class
Inheritance
Parent a class to another class to inherit it. Unlimited inheritance levels are supported. In this case, DemoClass
would inherit properties and values from Object
Module
Download this module then drag and drop it into ReplicatedStorage to use it
ObjectController.rbxmx (5.5 KB)