Contents Up Previous Next

Script modules

If you're working on a fairly large game, you'll find that your global script can quickly become rather large and unwieldy. This is where Script Modules come in -- they basically allow you to have lots of different global scripts, and split your code up accordingly.

The main global script still has to contain all the interaction functions (Look At Character scripts, Interact With Inventory scripts and so forth). But if you have any custom functions then you can put them in a seperate module in order to divide up your code. Modules have the added advantage that they can be easily exported and imported, if you want to share some of your code with other people, or even just move it from one game to another.

Script Modules are accessed via the "Module Manager" option on the Script menu. Each module has its own script header, which is where you place the import definitions for that module to allow the rest of your game to access its functionality.

Module order is important. A module can only use functionality in other modules that come before it in the list. The global script and room scripts can access all script modules, but modules cannot access the global or room scripts.

As an example, suppose you want to have a special AddNumbers function in a module. You'd create a new module in the Module Manager, then put this in its module header:

import function AddNumbers(int a, int b);
Then, in the module script you could put:
function AddNumbers(int a, int b) {
  return a + b;
}
As you can see, modules are based off exactly the same principles as the global script and script header, but allow you to split your code into more managable chunks.

Special functions

Can script modules use special functions like game_start and repeatedly_execute? Well, yes and no. Script modules can contain the following functions, and they will be called at the appropriate times just before the global script's function is:

All other special functions, such as dialog_request, will not be called even if they exist in a module. If you need modules to handle any of this functionality, you can simply create a custom function in the module and then call it from the global script.

The ClaimEvent command is supported for on_key_press, on_mouse_click and on_event. Calling it prevents the rest of the modules and global script from being called.

Browser Based Help. Published by chm2web software.
1