HEADER0221 (10K)

First steps with Scripting

I am far from being an expert in the realm of scripting, but simple scripts are not too difficult to understand.
I will try to keep it very simple.

Let's say you want to open a door in a particular fashion. The normal way would be to apply an action special 11: Open Door to:

  1. a linedef with the player crosses trigger

    map_01 (42K)

    Example pwad

  2. a switch with the use trigger

    map_02 (60K)

    Example pwad

  3. a player enters/leaves a sector thing

    map_03 (59K)

    Example pwad

  4. kill a monster

    map_04 (64K)

    Example pwad

In all of those cases the player causes a single event, namely to open a door.

But how does one apply a script to do the same thing?
The structure of a script is thus:

#include "zcommon.acs"
script 1 (void)
// do some stuff

So, what does that mean? Let's take a look at each line.

#include "zcommon.acs" is very important. Without it the compiler will not know what to do.
Actually, zcommon.acs is a short version of including 3 separate definitions:

  1. zwvars.acs - world-variable declarations (this is usually empty)
  2. zdefs.acs - a list of all common zdoom definitions
  3. zspecial.acs - a list of all action specials

From time to time, check out https://github.com/rheit/acc/ for the latest versions.

If one wanted to, one could write this also as:

#include "zwvars.acs"
#include "zdefs.acs"
#include "zspecial.acs"
script 1 (void)
// do some stuff

script 1 (void) tells the compiler the script is of type (void). There are other types. GZDoom now allows to specify a script by name instead of by a number. For example:

script"Open a Door" instead of script 1"

(void) is used when some event is triggered in the map.

Each body of the script must be within curly brackets:
{ at the start of the script
} at the end of the script

// can be used to type some comment to remind you what that line is about in case you come back to it later

Therefore, to use a script to open a door, as in the above examples, the script would look like this:

#include "zcommon.acs"
script 1 (void)
// 11: Door_Open (tag, speed, lighttag);
// Open a Door after the Demon is killed

	 Door_Open (100, 10, 0);

// 100 is tag of the door sector
// 10 is speed of the door opening up
// keep lighttag at 0

Once you finish the script text, it must be compiled. Press the compile button. If an error creeps in, then the compiler will show a message at the bottom of the window.

script1b (30K)

Here it is in action when killing a monster:

map_05 (63K)

Example pwad

Now, rather then attaching the action special 11: Open_Door as in the top examples, the action special
80: Script_Execute is attached. Do not forget to specify the script number.

With ACS being a derivative of the C language, many possibilties open up.