XSkriptTutorial.Kapitel4-1
Search:
print pdf

Chapter 4 - Message windows for advanced usersXScript-tutorial4.2 The 1. quiz

MissingLink für Verweise auf noch nicht erstellte Abschnitte:

Begriffe, für die auf eine Definition verwiesen wird; Altes grün 33AA11

Chapter 4.1 The basic framework


At the beginning we want to make us thinking about what exactly should really make our script, then it to create a basic framework.

Our trivia game will consist of three small quizzes, each with three questions. The first Quiz game will be a kind of multiple choice game (as well as "Who becomes a millionaire"), the second Quiz consists of riddles whose answers must be entered via the keyboard and the third Quiz analyzed the computational power of the player's head. If the player at the end of all questions answered correctly, he wins the game, and receive a price (credits). Regardless of whether the player has now answered all the questions correctly or not, is again at the end a summary shall be issued.

So it should now be possible to create a basic framework for our script. So that we can test the same from the beginning, if our script works the way we imagine it, we can spend the same in each procedure, a text message.
markieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
program Quiz;
const
  Introduction = 'Welcome to our little'
               + '<yellow>Ga<bluebold>me <green>show<white>.'
               + #13#10#13#10
               + 'If you feel good hit, you will be richly rewarded.';
  IntroQuiz1 = 'In the first game, you get asked questions around the topic of X-Force. '
             + 'All you ever get four possible answers to choose from. Choose wisely! ';
  IntroQuiz2 = 'Now it is much harder. Here are a few (the lighter) '
             + 'From some of my favorite puzzle games of earlier times roll.';
  IntroQuiz3 = 'In our third Game, it is about head rake ...';

  // ... here later follow the questions and answers of a quiz game

  Won = 'Congratulations! You have beaten quite excellent, and all '
      + 'Questions answered correctly. Therefore, there is a hefty reward. ';
  Lost = 'It looks like our quiz was too hard for you. You could not answer all questions '
       + 'correctly. We will see if you have earned at least a consolation prize ...';


procedure Quiz1;
begin
  game_api_messageBox(IntroQuiz1);
end;

procedure Quiz2;
begin
  game_api_messageBox(IntroQuiz2);
end;

procedure Quiz3;
begin
  game_api_messageBox(IntroQuiz3);
end;

procedure Summary;
begin
  game_api_messageBox('...');
end;

procedure StartMission;
begin
  game_api_messageBox(Introduction);

  Quiz1; // multiple choice
  Quiz2; // puzzle
  Quiz3; // head rake

  mission_win;
end;

procedure OnMissionWin;
begin
  game_api_messageBox(Won);
  Summary;
end;

procedure OnMissionLose;
begin
  game_api_messageBox(Lost);
  Summary;
end;

begin
  MissionName := 'Quiz';
  MissionType := mzUser;
end.

The above script should be easy to understand with what has been learned. There are only three small innovations. On the one hand, we have first used the type of missionmzUser, so we have to call the procedure in line 49mission_win to end our script.

The second and 3rd Constant innovation is theIntroduction. In line 4, the game show based on the text is highlighted by colorful tags. The tags themselves are not displayed here (note: this only works in the game - in medit are the tags not recognized, but simply issued as part of the message - so you'll have to test so start X-Force). Which tags are allowed, and what implications they have for, you can read in the reference under game_api_messageBox.

Finally emerged in row 5, the strange symbols#13#10#13#10 on. This is an opportunity to characters from the ASCII character set specified. For this, the character is followed by a decimal number used#. #13 stands for "carriage return" , and#10 for "Line Feed". Under Microsoft Windows, the combination of "Carriage Return" + "Line Feed" used to end a line (line break). With#13#10#13#10 we finish the current line, and generate an additional blank line (as if you are in a word processing program the Enter key twice omitted). You can but as it, any other characters - especially special characters that you might be missing on the keyboard produce. With the use of ASCII characters is to be noted that thisnot as plain text between'...' allowed to stand. A complete ASCII table can be found e.g. here: http://www.webplain.de/software/ascii-tabelle.php?show=0

Sequence of procedures and functions


Since we now have quite a lot of procedures in our script, it's time to say something about the order. Generally, it is so that a procedure / function must be declared before his call in the script. Declared in this context means something like "the name and the parameters of a function / procedure to the [[Definition: Compiler Compiler]] make known". This is necessary because the syntax check is performed before each start of script (and saving) from the top to the bottom. Pushes them to an unknown command (for example, a procedure that is declared only a few lines later) here, then it is obviously an error. For our framework does this mean that, for example Summary beforeOnMissionWin andOnMissionLose must stand. Analogous to Quiz1,''come Quiz2 and Quiz3 before mission start.

Strictly speaking, what we have done in our scripts yet no declaration has been, but a definition of the procedures / functions. Definition means that the same instructions that are to be executed in a procedure that specifies with. A definition is automatically a declaration (if this has not happened before now). Especially in scripts with many functions / procedures that call each other often, but it can be very difficult (or even impossible) to define them in the correct order. Therefore, it is possible, functions / procedures to start a script already declared. After that the order does not matter anymore, because the name and parameter list are already known. A declaration looks basically exactly like this, as the first Line of the definition, the only forward; must append behind. For our basic framework could then look something like this:

markieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
program Quiz;
const
  Introduction = 'Welcome to our little'
               + '<yellow>Ga<bluebold>me <green>show<white>.'
               + #13#10#13#10
               + 'If you feel good hit, you will be richly rewarded.';
  IntroQuiz1 = 'In the first game, you get asked questions around the topic of X-Force. '
             + 'All you ever get four possible answers to choose from. Choose wisely! ';
  IntroQuiz2 = 'Now it is much harder. Here are a few (the lighter) '
             + 'From some of my favorite puzzle games of earlier times roll.';
  IntroQuiz3 = 'In our third Game, it is about head rake ...';

  // ... here later follow the questions and answers of a quiz game

  Won = 'Congratulations! You have beaten quite excellent, and all '
      + 'Questions answered correctly. Therefore, there is a hefty reward. ';
  Lost = 'It looks like our quiz was too hard for you. You could not answer all questions '
       + 'correctly. We will see if you have earned at least a consolation prize ...';

procedure Quiz1;forward;
procedure Quiz2;forward;
procedure Quiz3;forward;
procedure Summary;forward;

procedure StartMission;
begin
  game_api_messageBox(Introduction);

  Quiz1; // multiple choice
  Quiz2; // puzzle
  Quiz3; // mental math

  mission_win;
end;

procedure OnMissionWin;
begin
  game_api_messageBox(Won);
  Zusammenfassung;
end;

procedure OnMissionLose;
begin
  game_api_messageBox(Lost);
  Zusammenfassung;
end;

procedure Quiz1;
begin
  game_api_messageBox(IntroQuiz1);
end;

procedure Quiz2;
begin
  game_api_messageBox(IntroQuiz2);
end;

procedure Quiz3;
begin
  game_api_messageBox(IntroQuiz3);
end;

procedure Summary;
begin
  game_api_messageBox('...');
end;

begin
  MissionName := 'Quiz';
  MissionType := mzUser;
end.

Before we go now to the first Turn to quiz, we want to introduce more fast 3 global integer variables, with whom we can count how many answers in the quizzes were answered correctly. This we will need later for the evaluation.
markieren
1
2
3
4
5
6
7
program Quiz;
const
 / / ...
var
  Q1_correct: Integer;
  Q2_correct: Integer;
  Q3_correct: Integer; 

So now we can turn to the next chapter ...


Recent Changes - Edit Menue
Page last modified on 01.12.2011, 19:49 by Painkiller347
Edit Page - Attributes - Page History