MissingLink für Verweise auf noch nicht erstellte Abschnitte:
Begriffe, für die auf eine Definition verwiesen wird; Altes grün 33AA11
First steps
In this chapter, the main structure of X-Script is explained. X-Scripts can be created with the X-Force mission editor (medit.exe), which is located in the main directory of X-Force.
After starting medit, adjustments can be made with
File → Settings, in order to adjust the editor to your personal preferences.
If there are more special requests concerning font type/size, background colour or syntax highlighting, browsing through the forum and this wiki should help.
The base structure for each script
All others can start immediately. A new script is created with
File → New. This script contains by default a base structure with the essential elements, which have to be present in each script. The basic structure will be explained in the following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
program YourName;
procedure StartMission;
begin
end;
begin
MissionName := 'YourName';
MissionTyp := mzUFO;
end. |
In the first line, a name is assigned to every script. This is done with the
reserved word program, which is followed by the favoured name. After that a semicolon finishes the
instruction.
The given name has to be an
identifier and doesn't play a role within the script. It helps to identify the script at the first glance. Therefore a significant name should be chosen (not 'testscript' or 'script1'!).
The semicolon always ends an instruction. Unlike in the "real" Pascal, it isn't required in X-Script, but for clarity it should nevertheless always be used.
After that, global declarations and/or definitions are given. Global implies, that these declarations and definitions are valid for the whole script. That contains global
constants and
variables, as well as own
functions and
procedures.
Some aspects will be discussed in more detail later. At this point it is important to know, that the names can be chosen freely. They just have to comply to the rules of the identifier. X-Script contains some special procedures and functions which have to have special names. The only procedure which has to be included in each script is
StartMission. This script will be called automatically while starting the script and should contain everything which is needed for running it (like creating UFOs or ground combat missions). We will discuss further special procedures like OnMissionWin and OnMissionLose later.
In between the final
begin ... end (line 12-19), only the mission name and type should be defined (unlike as in Pascal). X-Force can access the mission name directly, and it will later on eventually be used, in order to present a ingame todo-list. For the name an arbitrary string can be used.
A few more remarks on
begin ... end:
This is as a whole an
instruction block, which is used in X-Script each time instructions should be combined. This
begin ... end will gain importance later on, when
conditions or
loops are used. Normally, an instruction block will be terminated by a semicolon as every single instruction. The only exception is the terminal instruction block of a script, which ands with a dot after the
end (line 19).
Comments:
In addition to the programme code itself, illustrating
comments should always be used. This has the advantage, that others (or oneself after some time) can comprehend, what was done. Comments will be completely ignored while processing the script. In principal, there exist two possibilities for giving comments. The first one is, to begin comments with
//. This is also preferably used in the turorial. Whatever follows the
// will be ignored, while processing the script.
Alternativly, one can put a comment in corly brackets
{ ... }. The comment doesn't end at the end of the line, but at the closing curled bracket
'}' . The same way works
(* ... *). The latter one should be used, in order to shield code sections for testing purposes. The curled brackets should be used, in order to explain coding sections extensively.
You will always be in dispute with commenting. As a programmer, one is as a general rule to lazy, to comment sufficiently. But you should always be reminded, that 1. perhaps someone else wants to understand / modify / extend your script or use it as a suggestion and 2. you yourself perhaps want to change a few things after some time. You should try to do "as much as possible but as little as necessary". Essential shouldn't be
what you have done, but
why you have done it that way and not another.