Create Your Own Modules - coldrockgames/doc-scriptor GitHub Wiki
Creating a module in Scriptor is as simple as creating any script, with just a few differences:
- No Compilation or Execution Needed:
Modules are passive pieces of code and do not require compilation or execution when created. They are only compiled and executed when
#include
d in another script. - No Owner:
Modules do not have an owner until they are included in a script. At that point, they inherit the owner of the script they are#include
d in.
How to Create a Module
To create a module, use the scriptor_add_module(...)
function (see Module Functions) instead of new Scriptor(...)
, which you would do, when you create a script.
Example: Creating a Module
scriptor_add_module("roll_dice", @"
self.dice_result = roll_dice(6)
");
In this example:
- A module named
roll_dice
is created. - The result of the roll is stored in the
dice_result
variable of the owner of the script.
Using the Module
Once created, the module can be included in any script using #include
.
#include roll_dice
if self.dice_result == 6 self.combat.opponent.die()
In this script:
- The
roll_dice
module is included and executed. - The result of the dice roll (
self.dice_result
) is checked. - If the result is 6, the opponent's
die()
method is called.