Mapster32 Scripting

From EDukeWiki
Jump to navigation Jump to search

Mapster32 Scripting M32 script commands M32 script variables


Mapster32 can be scripted by using a language derived from CON. You can either issue commands directly to the editor with the "do" 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

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>") to take effect. Simply using "enableevent" shows a list of defined event and their activation state.

States

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 variables.
  • 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). for is a special case because whether and how the current sprite is set depends on the iteration type.

Key access

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. Events that are fired every main iteration are: EVENT_KEYS3D, EVENT_OVERHEADEDITOR (those come after most key checks have been made, so you won't be able to redefine hardcoded keys), and EVENT_KEYS2D (this one comes before most key checks have been made).

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"; tsprite[i].owner is the corresponding sprite index.