Mapster32 can be scripted by using a language derived from CON. You can either issue commands directly to the editor with the "do" OSD command or load a script file (extension: .m32) by using "include <filename>" on the console. Events, states and quotes can be redifined, while multiple definitions of defines, gamevars and gamearrays are ignored.
Events are defined in the same way as in CON (with onevent and endevent), but must be enabled at the console (with "enableevent <event name or number>" or "enableevent all") to take effect. Simply using "enableevent" shows a list of defined events and their activation state.
States (subroutines) are defined between defstate and ends and are called by using state. Specifying "1" for a gamevar flag will make that variable block-local, that is, every event and state, as well as the top level (in interactive execution) will have its own value of the variable.
Syntax changes from CON
- Structures and arrays can be written anywhere a gamevar is expected, even where they are written to.
- Some commands have short forms. In particular, all commands that contain varvar can be written without it, e.g. ifvarvarl becomes ifl.
- Some commands are of variable length, depending on preceding parameters. See sort and for in M32 script commands.
- "sprite[I]" can be omitted. (See below: current sprite). In other words, the current sprite's members can be accessed by simply prepending their name with a period, like ".picnum".
- Some commands accept variables in place of constants.
The current sprite
Some commands, like ifactor, act on an implicit current sprite. The current sprite is set by various commands (implicitly by for, insertsprite and dupsprite, and explicitly with seti) as well as some events (EVENT_INSERTSPRITE2D, EVENT_INSERTSPRITE3D). The current sprite index is held in the gamevar I (capital i). The command for is a special case because whether and how the current sprite is set depends on the iteration type.
To define custom shortcuts, you need to place appropriate checks for pressed keys in the desired event. This is accomplished by using ifholdkey and ifhitkey. The difference between the two is that the latter will reset the key status while the former will continue to act until the user releases the key. See M32 script variables for events that are fired every interation of the main loop.
Drawn sprite access
Sprites that are drawn to the screen are accessed in the EVENT_ANALYZESPRITES event using the tsprite.xxx sprite array, which can be indexed from 0 to spritesortcnt-1. To loop over all of them, use "for i drawnsprites". The index of the actual sprite that was drawn is held in tsprite[i].owner.