11-28-2019, 02:07 PM
Statements
Up to now, we were talking about data. But scripting means writing something that operates on that data. This is where statements come in.
Basically, a statement is one single line of script that "does something".
The following line is a statment:
_test = 0;
This statement is a simple assignment. The value 0 is assigned to the variable _test. A statement is always ended with a semicolon (";") character. If you forget the semicolon, the game will complain about a script error.
Multiple statements can be written on the same line, or on different lines:
_object = player;
_object moveInDriver _car; _object assignAsDriver _car;
The script can also be written like this:
_object = player; _object moveInDriver _car; _object assignAsDriver _car;
Or like this:
_object = player;
_object moveInDriver _car;
_object assignAsDriver _car;
The important thing is the order: A script always executes one statement at a time. So the _object = player; would be executed first, followed by the second statment, and the third statement. In the next chapter, we'll learn how to deviate from that order (with the use of conditional execution).
Remember the code datatype that we discussed briefly in the section about data types ? The code datatype is nothing else but a sequence of statements that are assigned to a variable. For example:
_code = {_object = player; _object moveInDriver _car; _object assignAsDriver _car;};
The code in curly braces is not executed directly, but written into a variable. Note: The same rules apply to code written as data as normal code: A Semicolon must end every statement, and the line can be broken in any way. So the above could be written as
_code = {
_object = player;
_object moveInDriver _car;
_object assignAsDriver _car;
};
or even
_code = {
_object
=
player;
_object
moveInDriver
_car;
_object
assignAsDriver
_car;
};
if you are feeling funky.
We will go into more detail on how to use code in variables when we discuss functions (including passing values into the function), but for now, suffice to say that the code in _code can be executed by
call _code;
To summarize:
Up to now, we were talking about data. But scripting means writing something that operates on that data. This is where statements come in.
Basically, a statement is one single line of script that "does something".
The following line is a statment:
_test = 0;
This statement is a simple assignment. The value 0 is assigned to the variable _test. A statement is always ended with a semicolon (";") character. If you forget the semicolon, the game will complain about a script error.
Multiple statements can be written on the same line, or on different lines:
_object = player;
_object moveInDriver _car; _object assignAsDriver _car;
The script can also be written like this:
_object = player; _object moveInDriver _car; _object assignAsDriver _car;
Or like this:
_object = player;
_object moveInDriver _car;
_object assignAsDriver _car;
The important thing is the order: A script always executes one statement at a time. So the _object = player; would be executed first, followed by the second statment, and the third statement. In the next chapter, we'll learn how to deviate from that order (with the use of conditional execution).
Remember the code datatype that we discussed briefly in the section about data types ? The code datatype is nothing else but a sequence of statements that are assigned to a variable. For example:
_code = {_object = player; _object moveInDriver _car; _object assignAsDriver _car;};
The code in curly braces is not executed directly, but written into a variable. Note: The same rules apply to code written as data as normal code: A Semicolon must end every statement, and the line can be broken in any way. So the above could be written as
_code = {
_object = player;
_object moveInDriver _car;
_object assignAsDriver _car;
};
or even
_code = {
_object
=
player;
_object
moveInDriver
_car;
_object
assignAsDriver
_car;
};
if you are feeling funky.
We will go into more detail on how to use code in variables when we discuss functions (including passing values into the function), but for now, suffice to say that the code in _code can be executed by
call _code;
To summarize:
- Every statement must be ended by a semicolon;
- Statments are executed in the order they appear in the script
- A series of statements can be assigned to a variable, and executed via the call command