-
Notifications
You must be signed in to change notification settings - Fork 0
Modules
Modules in the K2 Scripting Framework are essentially collections of K2 script files (.cfg) which are compiled into the K2 Framework script as a class. Each class has methods which are made of each individual K2 script. As a modder, you can call any of the available methods using the following syntax:
#$e# K2 <module name>.<method name> <options>A real world example looks like this:
#$e# K2 Array.new "my_array"This example creates a new array called “my_array”, whereas “Array” is the class name (which is also the name of the module) and “new” is the method of this class. “my_array” is an option.
To understand how these classes and methods come to be, here is a simplified example of how a class looks like in K2 script code:
@Example::__construct{
// Magic function which constructs the class. It will create itself
#@# "Example::__exec{";
@Example::__exec{
// Magic function that routes method calls. It will create itself
#@# "Example::__destruct{";
@Example::new{
// This is a custom method called "new"
#># -1 "Hello World";
#@# "Example::__destruct{";
@Example::__destruct{
// Magic function which destructs the class. It will create itself
#@# }Magic functions are class methods that are automatically created by the framework. You don’t have to do anything and they are primarily used internally by the framework. They do a lot of “magic” behind the scene which is why they are called “magic” ;)
Custom methods is what you will be writing most of the time. Think of them as miniature world triggers that you can call from anywhere at anytime. You can even pass variables to these methods, just like world triggers.