Mapster32 Scripting: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
update
Line 1: Line 1:
[[Mapster32 Scripting]] [[M32 script commands]] [[M32 script variables]]  
[[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.  
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  ==
== 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.  
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  ==
== States  ==
Line 18: Line 18:
*Some commands have short forms. In particular, all commands that contain ''varvar'' can be written without it, e.g. '''ifvarvarl''' becomes '''ifl'''.  
*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]].  
*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)
*Some commands accept variables in place of constants.
*Some commands accept variables in place of constants.


== The current sprite  ==
== 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.  
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.


== Key access  ==
== 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).  
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  ==
== 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.
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''.

Revision as of 14:21, 11 October 2009

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" 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

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

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)
  • 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.

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. 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.