📚
ClassLib
📚 ClassLib Repo
  • ClassLib
  • 📌Getting Started
    • ⚙️ Installation
    • 🎒 Examples
  • 🧰Scripting Reference
    • 📘 BaseClass
    • 📗 BaseClassEx
Powered by GitBook
On this page
  • 🗿 Static Functions
  • GetAll
  • GetCount
  • GetByID
  • GetParentClass
  • GetAllParentClasses
  • GetInheritedClasses
  • Inherit
  • ClassCall
  • ClassSubscribe
  • ClassUnsubscribe
  • SubscribeRemote
  • UnsubscribeRemote
  • 🦠 Methods
  • Constructor
  • Destructor
  • SetValue
  • GetValue
  • GetAllValuesKeys
  • IsValueBroadcasted
  • Call
  • Subscribe
  • Unsubscribe
  • CallRemote
  • BroadcastRemote
  • Clone
  • Destroy
  • GetClass
  • GetClassName
  • GetID
  • IsA
  • IsValid
  • IsBeingDestroyed
  • Super
  • SuperAll
  • 🚀 Events
  • ClassRegister
  • Spawn
  • Destroy
  • ValueChange

Was this helpful?

  1. Scripting Reference

📘 BaseClass

BaseClass is the class from which all ClassLib classes inherits

PreviousScripting ReferenceNext📗 BaseClassEx

Last updated 12 months ago

Was this helpful?


💂 AUTHORITY

This class can be spawned on both 🟧 and 🟦 side

Check out some examples for on the page


🗿 Static Functions

GetAll

Returns all instances from this class

— Returns (Table of all instances of the class)

local ret = BaseClass.GetAll()

for _, v in ipairs(ret) do
    print(v:GetID())
end

GetCount

Returns how many instances of this class exists

local ret = BaseClass.GetCount()

print(ret.." instances on BaseClass")

GetByID

Returns an instance of this class from the instance unique ID

local ret = BaseClass.GetByID(iID)
Type
Name
Default
Description

iID

The instance ID


GetParentClass

Returns the class from which this class inherits

local ret = BaseClass.GetParentClass()

GetAllParentClasses

Returns a sequential table of all classes from which this class inherits

local ret = BaseClass.GetAllParentClasses()

GetInheritedClasses

Returns a sequential table of all classes that inherit from this class

local ret = BaseClass.GetInheritedClasses()

Inherit

Creates a new class that inherits from this class

Synchronized instances will be networked to new players even if the instance was created before they were connected on the server

MyClass = BaseClass.Inherit(sClassName, bSync?)
Type
Name
Default
Description

sClassName

The name of the new class

bSync?

false

Whether to sync the creation/destruction of an instance of the class to all players


ClassCall

Calls an event on the class

BaseClass.ClassCall(sEvent, ...?)
Type
Name
Default
Description

sEvent

The name of the event to call

...?

The arguments to pass to the event


ClassSubscribe

Subscribes to an Event on the Class

Return false in the callback to unsubscribe from the event after the listener has been triggered

local ret = BaseClass.ClassSubscribe(sEvent, callback)
Type
Name
Default
Description

sEvent

The name of the event to listen to

callback

The callback to call when the event is triggered, return false to unsubscribe from the event


ClassUnsubscribe

Unsubscribes from all subscribed Events on this Class, optionally passing the function to unsubscribe only that callback

BaseClass.ClassUnsubscribe(sEvent, callback?)
Type
Name
Default
Description

sEvent

The name of the event to unsubscribe to

callback?

The callback to unsubscribe, or nil to unsubscribe to all events with the same name


SubscribeRemote

Subscribes to a remote event

BaseClass.SubscribeRemote(sEvent, callback)
Type
Name
Default
Description

sEvent

The name of the event to unsubscribe to

callback

The callback to call when the event is triggered, return false to unsubscribe from the event


UnsubscribeRemote

Unubscribes to a remote event

BaseClass.UnsubscribeRemote(sEvent, callback?)
Type
Name
Default
Description

sEvent

The name of the event to unsubscribe to

callback?

The callback to unsubscribe, or nil to unsubscribe to all events with the same name


🦠 Methods


Constructor

Called after an instance of the class is created

function BaseClass:Constructor(...?)
    -- Custom behaviour on instance spawn, with `self` being the instance
end
Type
Name
Default
Description

...?

The arguments to passed to the contructor when calling MyClass() as a function


Destructor

Called when an instance is about to be destroyed

Return false in the destructor to prevent an instance from being destroyed

function BaseClass:Destructor(...?)
    -- Custom behaviour on instance destroy, with `self` being the instance
end
Type
Name
Default
Description

...?

The arguments to passed to the contructor when calling my_instance:Destroy()


SetValue

Sets a key/value on the instance

my_instance:SetValue(sKey, xValue, bBroadcast)
Type
Name
Default
Description

sKey

Key

xValue?

Value

bBroadcast?

Whether to broadcast the key/value to all clients (server only)


GetValue

Gets a key/value from the instance

local ret = my_instance:GetValue(sKey, xFallback)
Type
Name
Default
Description

sKey

Key

xFallback?

Fallback value (if the key doesn't exist)


GetAllValuesKeys

Returns all the values of the instance set by SetValue

local ret = my_instance:GetAllValuesKeys(bBroadcastedOnly)
Type
Name
Default
Description

bBroadcastedOnly

false

Wether to only return broadcasted values


IsValueBroadcasted

Returns wether a key has it's value is broadcasted

local ret = my_instance:IsValueBroadcasted(sKey)
Type
Name
Default
Description

sKey

Key


Call

Calls an Event on the instance

my_instance:Call(sEvent, ...?)
Type
Name
Default
Description

sEvent

The name of the event to call

...?

The arguments to pass to the event


Subscribe

Subscribes to an Event on the instance

Return false in the callback to unsubscribe from the event after the listener has been triggered

local ret = my_instance:Subscribe(sEvent, callback)
Type
Name
Default
Description

sEvent

The name of the event to listen to

callback

The callback to call when the event is triggered, return false to unsubscribe from the event


Unsubscribe

Unsubscribes from all subscribed Events in this instance, optionally passing the function to unsubscribe only that callback

my_instance:Unsubscribe(sEvent, callback)
Type
Name
Default
Description

sEvent

The name of the event to unsubscribe to

callback?

The callback to unsubscribe, or nil to unsubscribe to all events with the same name


CallRemote

Calls a remote event, from the client to the server, or from the server to the client

my_instance:CallRemote(sEvent, ...?)
Type
Name
Default
Description

sEvent

The name of the event to call

...?

The arguments to pass to the event


BroadcastRemote

Broadcast a remote event from the server to all clients

my_instance:BroadcastRemote(sEvent, ...?)
Type
Name
Default
Description

sEvent

The name of the event to broadcast

...?

The arguments to pass to the event


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

my_instance:Clone(tIgnoredKeys?, ...?)
Type
Name
Default
Description

tIgnoredKeys?

The properties to ignore (must be a sequential table)

...?

The arguments to pass to the constructor


Destroy

Destroys the instance

my_instance:Destroy(...?)
Type
Name
Default
Description

...?

Arguments to pass to the destructor


GetClass

Returns the class table of the instance

local ret = my_instance:GetClass()

GetClassName

Returns the class name of the instance

local ret = my_instance:GetClassName()
print("My object's class name is "..ret)

GetID

Returns the ID of the instance

The ID is unique to it's class, and won't be re-used if the object gets destroyed

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

You can also call ClassLib.IsA(xAnyValue, tClass, bRecursive?)

my_instance:IsA(oClass, bRecursive)
Type
Name
Default
Description

tClass

The class to check

bRecursive?

false

Wether to check recursively


IsValid

Checks if the instance is valid

local ret = my_instance:IsValid()
print("My object is "..(ret and "valid" or "invalid"))

IsBeingDestroyed

Checks if the instance is being destroyed

local ret = my_instance:IsBeingDestroyed()
print("My object is "..(ret and "" or "not ").."being destroyed")

Super

Returns the class from which this instance class inherits

local ret = my_instance:Super()
print("My object's class inherits from "..ret:GetClassName())

SuperAll

Returns a sequential table of all classes from which this instance inherits

local ret = my_instance:SuperAll()

🚀 Events


ClassRegister

Called when a new class is inherited from this class

BaseClass.ClassSubscribe("ClassRegister", function(tInheritedClass)
end)
Type
Argument
Description

tInheritedClass

The instance that was spawned


Spawn

Triggered when an instance is created

BaseClass.ClassSubscribe("Spawn", function(self)
    -- BaseClass() was called
end)
Type
Argument
Description

self

The instance that was spawned


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)
Type
Argument
Description

self

The instance that is about to be destroyed


ValueChange

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)

— Returns (Amount of instances of the class)

— Returns (The instance, or nil if it doesn't exist)

— Returns (The super class)

— Returns (The super classes)

— Returns (The inherited classes)

— Returns (The new class)

To synchronize instances of a class you must your class on the side and spawn/destroy your instances on the 🟦 side

— Returns (The callback)

— Returns

— Returns (The callback)

If called from the 🟦 side, the 2nd argument is the player (or table of players) to which to send the event (in this case the varargs will start from 3rd argument instead of 2nd)

— Returns (The new instance)

— Returns

— Returns (The class name)

— Returns (Amount of instances of the class)

— Returns

— Returns (Wether the instance is valid)

— Returns (Wether the instance is being destroyed)

— Returns (The parent class)

— Returns (The list of parent classes)

instance

instance

Triggered when an instance has a value changed with

Client
Server
BaseClass
Examples
table
integer
table
table
table
table
table
function
boolean
function
Server
table
table
string
integer
boolean
boolean
boolean
table
table
Shared
Server
Inherit
:SetValue()
integer
string
boolean
string
any
string
function
string
function
string
function
string
function
any
any
string
any
boolean
string
any
boolean
string
string
any
string
function
string
function
string
any
string
any
table
any
any
table
boolean
table
BaseClass
BaseClass
🧰
Page cover image