-
Notifications
You must be signed in to change notification settings - Fork 0
How to use
To start using GML-Classes, just add gml_classes
script to your project.
To define class use a special keywords class
and define
.
class MyClass define
{
//...
}
If you need to inherit from another class, then use keyword extends
like this:
class MyClass extends MyParentClass define
{
//...
}
A constructor is a method that is called when an instance of a class is created.
A destructor is a method that is called when an instance of a class is deleted.
The constructor method must be named _constructor
, and the destructor - _destructor
.
class MyClass define
{
_constructor = function() {
// initialize all variables here
}
_destructor = function() {
// deinitialize here, free memory
}
}
To call parrent method use keyword super
.
class MyClass extends MyParentClass define
{
_constructor = function(name) {
// call parent constructor
super._constructor(name);
// do something else
}
_destructor = function() {
// call parent destructor
super._destructor();
}
doSomething = function(arg0, arg1, arg2) {
// call parent method
super.doSomething(arg0, arg1, arg2);
// do something else
}
}
To instantiate a class, you must use the create
function instead of the new
keyword as you would for structures, otherwise the class instance structure will not be initialized properly and you will get an error.
To delete class instance you must use destroy
function instead of delete
keyword.
// instantiate class
inst = create(MyClass, "Teapot");
// use it
inst.doSomething();
// don't forget to delete it with the `destroy` function
destroy(inst);