Skip to content

Module Functions

Kiki edited this page Dec 25, 2024 · 8 revisions

Modules in Scriptor operate outside of individual scripts and become globally available once added. They provide a flexible way to reuse code efficiently across your project.

What is a Module?

In short terms, a module is any script or part of a script that you want to reuse.

Including a module in your script works similarly to the event_inherited() function of gml. However, it is not a traditional function call. Instead, the source code of the base event will be copied at the position, where event_inherited() resides.

Key Advantages:

1. Performance Efficiency:
Unlike deep inheritance structures in GML, where constructor chains might reduce performance, module inclusion incurs no runtime cost. Regardless of how complex your inheritance hierarchy is, the event code remains a single function without nested calls.

2. Compile-Time Inclusion:
The #include statement works at compile time, meaning the module's code is inserted directly into the script during compilation. This ensures seamless rebinding and recompilation.

Syntax: Including a Module

#include your_module

The `#include´ statement places the content of the specified module exactly at its location in the script. You can include anything, from a single line of code to an entire sequence, as a module.

Managing Your Modules

Modules are managed using global functions, eliminating the need for instantiating classes. Below are the available functions for working with modules:

Adding a Module

/// @func scriptor_add_module(_name, _source_code)
/// @desc If a module with the specified name already exists, it is overwritten
function scriptor_add_module(_name, _source_code) {

Removing a Module

/// @func scriptor_remove_module(_name)
/// @desc Delete a module. If the specified module does not exist, this is silently ignored
function scriptor_remove_module(_name) {

Checking Module Existence

/// @func scriptor_module_exists(_name)
/// @desc Query existance of a module. Returns bool.
function scriptor_module_exists(_name) {