Modules¶
This section covers the three environments where modules exist: Server
, Client
, and Shared
. Modules behave in the same way in each location.
Usage¶
Like other framework objects, modules can also have Init
and Start
methods. However, these methods are optional.
The biggest difference with Modules is that they are lazy-loaded. In other words, modules are not necessarily loaded at the beginning of runtime. Instead, they are loaded the first time they are referenced. What this means is that you can have a large collection of modules that you reuse within many projects, but are not necessarily eating up much memory.
Lazy-loading is handled in the background, and it should not affect anything regarding the way you use a module. The most noticeable difference is that the Init
and Start
methods will not be invoked until the first time a module is referenced.
Like any ModuleScript on Roblox, modules have the same structure:
1 2 3 4 5 |
|
Classes¶
The Modules folder is the preferred location for classes. A Lua pseudo-class will usually look something like this at its core:
1 2 3 4 5 6 7 8 9 10 11 |
|
Framework access¶
With classes, the Aero Start
and Init
methods are also available, and are invoked as static methods once. In other words, the methods are not invoked on individual objects created from the class, but are invoked on the class itself. This is useful for referencing AGF modules that the class needs to use. For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Alternatively, the framework is also injected into the class, thus each object can still access AGF modules, just like other modules:
1 2 3 4 |
|
Object Events¶
Creating events is very useful for custom objects, but it is important that these events are properly registered and cleaned up. It is recommended that the ListenerList and/or Maid class is used, as well as a custom-defined Destroy method on your object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Now, a MyClass
instance could be used as such:
1 2 3 4 |
|
Client/Server Communication¶
Allowing class objects to communicate between the server/client boundary is the same as other objects within the framework. For instance, an object on the client invoking the server:
1 2 3 |
|
Prevent Init
or Start
¶
If you are trying to use a module that already has a Start
or Init
method that doesn't relate to AeroGameFramework (e.g. a 3rd-party module not designed for the framework), then you can prevent the framework from invoking these methods. This is done by setting the PreventInit
and PreventStart
flags on the settings module for the given module.
For more info, see the Settings section.
Third-Party Modules¶
When using third-party modules within AGF, it is recommended to use Standalone
mode.
For more info, see the Third-Party section for settings.