07-18-2019, 01:50 PM
(This post was last modified: 07-20-2019, 12:31 AM by Varanon.
Edit Reason: Typos
)
Introduction
A lot of people see scripting as an arcane thing that no one can fully understand, and while it's true that scripting topics can go from the trivial to the extreme, most practical scripting used by mission designers is actually pretty simple.
The daunting part is always that, when faced with an SQF code, and without the knowledge of what exactly it is you are seeing, everything looks arcane and incomprehensible. But at it's core, it's rather simple.
I will use this thread as sort of mini scripting guide. The goal is to give you just enough scripting knowledge to do simple scripts that allow you to do what you need them to do within your mission. It's goal is not an exhaustive programming course, and with what I present here, you might not be able to write complex code, but again, this is not the intention.
Script organization
Scripts are usually organized in files ending in ".sqf". When such a file is executed, the script interpreter in Arma starts executing the commands in the file starting with the first command, and then going on to the next, and the next, and so on. This is an important thing to note, and even though it might sound trivial, it's the essence of how a script works.
Some scripts, like init.sqf, are executed automatically at the start of the mission. A full table of all those "automatic" scripts can be found here, but for our purposes, we will stick to init.sqf as the root of all scripting in Arma. If you need something initialized, this is where to put it. You can call other scripts from within init.sqf using certain script commands, which we will touch on later.
Another way of executing script commands is from within the editor's console. This is useful for testing small script pieces and/or verifying the result of script commands.
Anything entered into the Execute field can be executed either locally (LOCAL EXEC), on the server (SERVER EXEC, multiplayer only) or on all clients and the server (GLOBAL EXEC, multiplayer only).
The Watch fields can be filled with code that produces a result, and the result will be displayed below the field.
To summarize what this chapter introduced:
A lot of people see scripting as an arcane thing that no one can fully understand, and while it's true that scripting topics can go from the trivial to the extreme, most practical scripting used by mission designers is actually pretty simple.
The daunting part is always that, when faced with an SQF code, and without the knowledge of what exactly it is you are seeing, everything looks arcane and incomprehensible. But at it's core, it's rather simple.
I will use this thread as sort of mini scripting guide. The goal is to give you just enough scripting knowledge to do simple scripts that allow you to do what you need them to do within your mission. It's goal is not an exhaustive programming course, and with what I present here, you might not be able to write complex code, but again, this is not the intention.
Script organization
Scripts are usually organized in files ending in ".sqf". When such a file is executed, the script interpreter in Arma starts executing the commands in the file starting with the first command, and then going on to the next, and the next, and so on. This is an important thing to note, and even though it might sound trivial, it's the essence of how a script works.
Some scripts, like init.sqf, are executed automatically at the start of the mission. A full table of all those "automatic" scripts can be found here, but for our purposes, we will stick to init.sqf as the root of all scripting in Arma. If you need something initialized, this is where to put it. You can call other scripts from within init.sqf using certain script commands, which we will touch on later.
Another way of executing script commands is from within the editor's console. This is useful for testing small script pieces and/or verifying the result of script commands.
Anything entered into the Execute field can be executed either locally (LOCAL EXEC), on the server (SERVER EXEC, multiplayer only) or on all clients and the server (GLOBAL EXEC, multiplayer only).
The Watch fields can be filled with code that produces a result, and the result will be displayed below the field.
To summarize what this chapter introduced:
- Scripts are kept in files ending in "sqf", which are read and executed sequentially
- There are script files that are executed automatically at mission start, like init.sqf
- The Console is a handy way of testing scripts, and verifying the result of certain script pieces