π BaseClass
BaseClass is the class from which all ClassLib classes inherits
πΏ Static Functions
GetAll
GetAll
Returns all instances from this class
β Returns table (Table of all instances of the class)
local ret = BaseClass.GetAll()
for _, v in ipairs(ret) do
print(v:GetID())
end
GetCount
GetCount
Returns how many instances of this class exists
β Returns integer (Amount of instances of the class)
local ret = BaseClass.GetCount()
print(ret.." instances on BaseClass")
GetByID
GetByID
Returns an instance of this class from the instance unique ID
β Returns table (The instance, or nil
if it doesn't exist)
local ret = BaseClass.GetByID(iID)
GetParentClass
GetParentClass
Returns the class from which this class inherits
β Returns table (The super class)
local ret = BaseClass.GetParentClass()
GetAllParentClasses
GetAllParentClasses
Returns a sequential table of all classes from which this class inherits
β Returns table (The super classes)
local ret = BaseClass.GetAllParentClasses()
GetInheritedClasses
GetInheritedClasses
Returns a sequential table of all classes that inherit from this class
β Returns table (The inherited classes)
local ret = BaseClass.GetInheritedClasses()
Inherit
Inherit
Creates a new class that inherits from this class
β Returns table (The new class)
MyClass = BaseClass.Inherit(sClassName, bSync?)
ClassCall
ClassCall
Calls an event on the class
BaseClass.ClassCall(sEvent, ...?)
ClassSubscribe
ClassSubscribe
Subscribes to an Event on the Class
β Returns function (The callback)
local ret = BaseClass.ClassSubscribe(sEvent, callback)
ClassUnsubscribe
ClassUnsubscribe
Unsubscribes from all subscribed Events on this Class, optionally passing the function to unsubscribe only that callback
BaseClass.ClassUnsubscribe(sEvent, callback?)
SubscribeRemote
SubscribeRemote
Subscribes to a remote event
BaseClass.SubscribeRemote(sEvent, callback)
UnsubscribeRemote
UnsubscribeRemote
Unubscribes to a remote event
BaseClass.UnsubscribeRemote(sEvent, callback?)
π¦ Methods
Constructor
Constructor
Called after an instance of the class is created
function BaseClass:Constructor(...?)
-- Custom behaviour on instance spawn, with `self` being the instance
end
Destructor
Destructor
Called when an instance is about to be destroyed
function BaseClass:Destructor(...?)
-- Custom behaviour on instance destroy, with `self` being the instance
end
SetValue
Sets a key/value on the instance
my_instance:SetValue(sKey, xValue, bBroadcast)
GetValue
Gets a key/value from the instance
local ret = my_instance:GetValue(sKey, xFallback)
GetAllValuesKeys
Returns all the values of the instance set by SetValue
local ret = my_instance:GetAllValuesKeys(bBroadcastedOnly)
IsValueBroadcasted
Returns wether a key has it's value is broadcasted
β Returns boolean
local ret = my_instance:IsValueBroadcasted(sKey)
Call
Call
Calls an Event on the instance
my_instance:Call(sEvent, ...?)
Subscribe
Subscribe
Subscribes to an Event on the instance
β Returns function (The callback)
local ret = my_instance:Subscribe(sEvent, callback)
Unsubscribe
Unsubscribe
Unsubscribes from all subscribed Events in this instance, optionally passing the function to unsubscribe only that callback
my_instance:Unsubscribe(sEvent, callback)
CallRemote
CallRemote
Calls a remote event, from the client to the server, or from the server to the client
my_instance:CallRemote(sEvent, ...?)
BroadcastRemote
BroadcastRemote
Broadcast a remote event from the server to all clients
my_instance:BroadcastRemote(sEvent, ...?)
Clone
Clone
Clones the instance, and return the new clone with the same values (except it's ID)
Optionally, you can ignore some properties, so they won't be copied
β Returns table (The new instance)
my_instance:Clone(tIgnoredKeys?, ...?)
Destroy
Destroy
Destroys the instance
my_instance:Destroy(...?)
GetClass
GetClass
Returns the class table of the instance
β Returns table
local ret = my_instance:GetClass()
GetClassName
GetClassName
Returns the class name of the instance
β Returns string (The class name)
local ret = my_instance:GetClassName()
print("My object's class name is "..ret)
GetID
GetID
Returns the ID of the instance
β Returns integer (Amount of instances of the class)
local ret = my_instance:GetID()
IsA
Checks if the instance is from a passed class, or from a class that inherits from the passed class
β Returns boolean
my_instance:IsA(oClass, bRecursive)
IsValid
IsValid
Checks if the instance is valid
β Returns boolean (Wether the instance is valid)
local ret = my_instance:IsValid()
print("My object is "..(ret and "valid" or "invalid"))
IsBeingDestroyed
IsBeingDestroyed
Checks if the instance is being destroyed
β Returns boolean (Wether the instance is being destroyed)
local ret = my_instance:IsBeingDestroyed()
print("My object is "..(ret and "" or "not ").."being destroyed")
Super
Super
Returns the class from which this instance class inherits
β Returns table (The parent class)
local ret = my_instance:Super()
print("My object's class inherits from "..ret:GetClassName())
SuperAll
SuperAll
Returns a sequential table of all classes from which this instance inherits
β Returns table (The list of parent classes)
local ret = my_instance:SuperAll()
π Events
ClassRegister
ClassRegister
Called when a new class is inherited from this class
BaseClass.ClassSubscribe("ClassRegister", function(tInheritedClass)
end)
Spawn
Spawn
Triggered when an instance is created
BaseClass.ClassSubscribe("Spawn", function(self)
-- BaseClass() was called
end)
Destroy
Destroy
Triggered when an instance is about to be destroyed
BaseClass.ClassSubscribe("Destroy", function(self)
-- Destroy was called
end)
-- or
my_instance:Subscribe("Destroy", function(self) end)
ValueChange
ValueChange
Triggered when an instance has a value changed with :SetValue()
BaseClass.ClassSubscribe("ValueChange", function(self, sKey, xValue)
print("New key/value set: "..sKey..":"..tostring(xValue))
end)
-- or
my_instance:Subscribe("ValueChange", function(self, sKey, xValue) end)
Last updated
Was this helpful?