π Examples
Some simple examples on how to use ClassLib
Creating a new class
Let's create a new class that inherits from BaseClass
-- Creates a new Class called "Person" inheriting from BaseClass
-- and stores it in the global variable Person
Person = BaseClass.Inherit("Person")
-- You can also create a new class that inherits from an inherited class
-- Let's create an Employee class, which will inherit from Person and BaseClass
Employee = Person.Inherit("Employee")
-- Spawn an instance of this class using the default constructor
local my_employee = Employee()
-- Destroy an instance by using the default destructor
my_employee:Destroy()Constructor/Destructor override
You can create your own Constructor/Destructor for your classes, that will allow to control the behaviour of your class when an instance is created or destroyed
Storing Data
You can store data on any instance, either in a classic key/value indexation
You can also use the :SetValue and :GetValue methods, which triggers "ValueChange" events on the class and on the instance it's called on
Adding new Methods
Adding or overriding methods to your classes is easy, let's say we want to add a new method for Person, we just do that:
Then you can call your cool method!
Local Events
It's possible to trigger local events on a class or an instance, example:
Synchronized Classes
To synchronize instance creation/destruction on a class, you must follow these simple steps
Define your class on the shared side, and pass
trueon the sync parameter of Inherit
After that, spawn/destroy your instances on the π¦ Server side
Network Events
It is also possible to trigger custom events on instances of your Class, using the methods CallRemote or BroadcastRemote like in the examples above:
From Server to Client
Or from Client to Server
Cloning Instances
You can clone instances very easily, it's doable with the :Clone() method
To filter the key/values that will be cloned, you can use the ignored keys parameter of :Clone(), like how it's done in the following example:
Last updated
Was this helpful?
