There will be no miraculous revelations here, we master writing scripts
by writing our own scripts. No one will put this skill in our brain with a
magic spell, like no one's doping or instruction will replace the
athlete's own training. However, it's good to know how to do push-ups and
where the nearest gym is. Below - about this, figuratively, of
course...
1. About starting
It is hardest to get started, so you need good motivation to try and
not be discouraged by encountered difficulties. Motivation can arise
from the irritation, that the game is not doing something, that we
think, it should do. Or from a dream, that something new could happen in
our gameplay. Or from the excess of free time...
At the beginning I suggest to define, or even point out exactly, what
our first script should do. Seems subjective matter, whether it would be
better to start with something modest, whether to jump into deep waters
right away. Depends on the need, that motivates us and the size of our
ambitions.
2. What is a script
Knowing what we want, we can try to explain it to the computer. The SQF
script is an algorithm, or instruction. In a way understandable to the
so-called game engine (its core program) tells, what the game should do.
This instruction is read and executed just after running the scenario in
which folder we will place the file or files of our script (see
CHAPTER 1: what are SQF scripts used for and how to run them?
).
Writing the simplest script is a matter of seconds and one line, on the other hand there are quite a few ambitious projects that have been developed over the years and cover tens of thousands of code lines. I warn you loyally - it's a trap! Man starts wanting to add a flavor to his game, which is lacking, and it may turn out that writing scripts become more fun for him than playing. Such a culprit soaks into scripting completely, preferring to create than to play, until one day he wakes up writing a blog with tips for beginners...
Same, as this statement consists of words, that form sentences, so a
script consists of suitably combined into expressions variables,
commands, etc.
Creating a script resembles solving a series of small logic puzzles: how to achieve something with given means. It is also an exercise in the preciseness of writing - the smallest mistake, a typo, missing semicolon, unpaired parenthesis almost always spoil the result and usually cause, that instead of the result we get from the computer only a litany of grudges, or enigmatic error logs. More about this in Chapter 4, about debugging code - removing errors from a script, that still, damn, doesn't work.
3. Variables
A variable is a string of characters we choose, a "word" for which we
"agree" with a computer, that stores (like a drawer with a label) a
certain value, e.g. a number, text, a set of numbers forming map
coordinates or an object in the scenario, e.g. player/player
unit.
Why not use values directly, but mask them under variable names? The values hidden under the variable name will often be changed by our script, these changes will often be unpredictable when writing the script, but the variable name will remain the same. It's easier to call someone by name on the street than to describe their current appearance every single time anew. This makes it very easy for us, even allows at all, to write good algorithms, but we will best find out about it in practice.
4. Commands
The command tells the computer what to do with some variable or
variables. For example, there is a command that says "place this object
there". In order for it to work, it must be given along with a variable
denoting the coordinates of "there" and, naturally, a variable denoting
"this object". Then the game knows what to put in which specific
place.
There are a lot of commands and they are coming with new versions of
Arma. Their whole creates a complete palette of our possibilities. We
will conctruct a script using them like blocks. There is no point in
trying to learn all of them by heart. Nothing by force. It is better to
focus only on those currently needed and use their documentation on an
ongoing basis. With time and subsequent scripts, the ones we use more
often will get stuck in our memory, the smoothness of writing code will
increase, and we'll get to know their collection better, which will help
us figuring out, what to do with which command.
But how one knows at the beginning what he have and what to use to achieve the intended goal? Command names usually reflect their purpose to some extent, so you can start by simply searching the list linked above by key words or their fragments.
5. Who asks, err less
If own search is not enough, we can ask for the help of the Arma's
modding community - they are really helpful people. No one will do the
work for us, but usually within a few days, if not hours, there appear a
few good souls ready to suggest something, direct somewhere, point out a
mistake.
Before we ask, how to do something, it is better to search the forum -
there is a good chance, that someone has asked the same question already
and got an answer.
The forum is also one of the main places to publish your own scripts. A
beginner (and not only) can learn really a lot by studying someone
else's scripts, that do something similar to his project. Well worth
it!
No comments:
Post a Comment