Skip to content
NikkoTC edited this page Sep 5, 2023 · 10 revisions

What is it?

GML-Classes is a script that provides some OOP functionality that allows you to define classes, their constructor and destructor, and call parent methods in overridden methods.

Why does it exist?

The main reason is convenience, in particular the convenience of calling parent methods.

When writing code, it may be necessary to implement more complex structures, with several levels of method inheritance.
But structures, due to the lack of an easy way to call the parent method, complicate the task.

To fix that, a special script called GML-Classes was created.
It is based on structs, but makes them more class-like in use.

Thanks to GML-Classes you can do this:
example full size

GML-Classes provides the following features:

  1. Constructor
    The constructor initializes the object (class instance) at the time of its creation.
    Here you can initialize data, reserve memory, resources, assign refs, etc.

  2. Destructor
    The destructor is executed when the object is destroyed.
    Thanks to it, you can deinitialize the object as you need.
    For example, break refs, free memory, resources, etc.

  3. Calling parent method
    The ability to call the parent methods allows you to get rid of duplication of the parent code in the overridden methods, which reduces the amount of code and, as a result, makes the code more maintainable and easier to read.