Difference between revisions of "Introduction to Arma Scripting"

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Layout)
 
(48 intermediate revisions by 16 users not shown)
Line 1: Line 1:
{{Stub}}
+
{{SideTOC}}
 +
== Introduction ==
  
During [[ArmA: Mission Editing|mission editing]] and [[ArmA: Addon Editing|addon editing]] you will often come into the situation, where your imaginations can't be implemented using the native methods of the editors (f.i. cutscenes in missions, special animations in addons). The '''solution''' is either to learn more about the editor (f.i. advanced features and methods) or [[ArmA: Scripting|scripting]].
+
This page should give beginners an overview of how to begin with scripting and where to find most of the information they need in the beginning. Some information might not be complete and can be found on other wiki pages.
  
[[Armed Assault|Armed Assault's]] '''scripting language''' gives you the possibility of influencing the game engine. With any combination of so-called [[:Category:ArmA: Scripting Commands|scripting commands]] you can create custom processes, that handle any specific needs and problems in a mission.
+
During [[ArmA: Mission Editing|mission editing]] and [[ArmA: Addon Editing|addon editing]] you may come across situations where actions or features you would like to have in your mission or addon cannot be accomplished using the basic (or even the more advanced) capabilities of the [[ArmA: Mission Editor|mission editor]] or within config files (in the case of addons). Some examples of this might be really cinematic cutscenes in missions or special animations for an addon.
  
== Terms ==
+
The '''solution''' to this is to take advantage of the game-engine's ability to call on an even more advanced feature known as [[Scripting|scripting]]. '''Arma''''s '''scripting language''' gives you a more direct control of core game features. With any combination of these '''[[:Category: Scripting Commands|commands]]''' and '''[[:Category: Functions|functions]]''' you can create custom processes that meet the specific needs of your mission or addon.
  
Before getting started, you should know the meaning of some terms.
 
  
; Script
+
== Before anything ==
: When speaking about a [[Script (File)|script]], the same accounts for [[Function|functions]], since functions are a kind of script.
 
  
; Game Engine
+
=== Is your idea necessary? ===
: The running program of the game which reads and executes your scripting commands.
 
  
== When Do I Need Scripting? ==
+
* Will players even notice or use what you want to script? Just because you can doesn’t mean you should. Sometimes less is more!
  
[[ArmA: Scripting|Scripting]] is primarily needed in [[ArmA: Mission Editing|user missions]] by the mission creator. The goal is to create processes that can't be done with the native features of the [[ArmA: Mission Editor|mission editor]]. So this is the first important check before you start scripting. Often the mission editor wants tiny features in a mission that '''arent't worth a script'''. Ask yourself, whether the user will notice and/or use the outcome of your script.
+
=== Is it possible to do this in the editor? ===
  
'''Be careful:''' Scripting isn't a solution to everything. The third step is to make sure whether your needs can be implemented with the scripting language. This can be hard for a beginner, but if you made sure the two above steps, it will be possible in most of the cases. If you aren't sure - just ask in the [http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi official forums] or at [http://www.ofpec.com OFPEC].
+
* [[Eden Editor]] is an incredibly powerful tool and with it alone one can achive a lot of things, even without writing a single line of [[SQF syntax|SQF]].
 +
* ''Poorly written'' scripts are often the reason for poor performance both in singleplayer and multiplayer scenarios.
  
=== Checklist ===
+
=== Can it be scripted using SQF? ===
  
Here is a short summed up checklist of the above mentioned points:
+
* This might be hard to answer, especially for beginners. Try to get as much information about what you want to do and what [[:Category: Scripting Commands|commands]] and [[:Category: Functions|functions]] there are before spending time on writing a script, just to find out it is ''not'' possible in the end.
  
# Can I do it with the native features? ([[ArmA: Mission Editor|mission editor]], [[ArmA: Addon Configuration|addon config files]], ...)
 
# Will the player notice and/or use it?
 
# Is it possible?
 
  
If all of the three points are answered with "Yes", go on and script it! But be warned: It won't always be easy. ;-)
+
Depending on your answer for these questions, you may want to rethink your approach.
  
== Scripting Code ==
+
{{Informative | '''Scripting''' is <u>not</u> a solution to everything.}}
  
The core of scripting is '''scripting code'''. The code consists of [[:Category:ArmA: Scripting Commands|scripting commands]] that tell the game engine what to do. These commands are executed one after another.
 
  
The code is written into special fields of the [[ArmA: Mission Editor|mission editor]] (see below) or into seperate files that are executed at some defined point (f.i. through [[ArmA: Triggers|triggers]]) during the running mission.
+
== Terms ==
 
 
=== Syntax ===
 
 
 
Every code has to follow a '''syntax'''. The syntax makes sure that the ''game engine'' can read and understand the code.
 
 
 
The primary syntax used in [[Armed Assault]] is [[SQF syntax]]. Read the corresponding article to inform yourself about it.
 
 
 
At some point you may also find scripts written in the deprecated [[SQS syntax]]. This syntax was the primary syntax in [[Operation Flashpoint]], but is considered deprecated since Armed Assault.
 
  
All scripting pages about Armed Assault will focus on [[SQF syntax]].
+
Before getting started, you should understand the meaning of these terms.
  
=== Layout ===
+
'''Data Types''':
 +
See [[Data Types]]
  
Code should be written in a specific '''layout'''. Complementary to the syntax, the layout assures that ''you and other coders'' can easily read the code. This is especially important when you haven't looked at your code for a long time and want to improve or change this code.
+
'''Algorithm''':
 +
In mathematics and computer science, an algorithm is an explicit specification of how to solve a class of problems. Algorithms can perform calculation, data processing and automated reasoning tasks.
  
* There should be '''only one [[Statement|statement]] per line''' in [[Script (File)|scripts]]. This doesn't concern script lines in the mission editor, since there all the code has to be written within a single line.
+
'''Interpreter''':
* Use '''spaces or tabs''' to indent code in [[Block|blocks]]. This way you can easily tell to which block some code belongs.
+
Reads your code from a script file and translates it into instructions for you to achieve your desired outcome/effect in the game.
  
Example:
+
'''Control Structures''':
 +
See [[Control Structures]]
  
Statement 1;
+
'''Syntax''':
+
* See [[SQF syntax]]
Block
+
* See [[SQS syntax]] (obsolete)
{
 
    Statement 2;
 
 
    Nested block
 
    {
 
        Statement 3;
 
        Statement 4;
 
    };
 
};
 
  
=== Comments ===
+
'''Script''':
 +
When speaking about a [[Script (File)|script]], we usually mean a .sqs or .sqf file.
  
You can and should write comments into your [[Script (File)|scripts]] that describe the purpose of your code. These comments are written in free text and completely ignored by the game engine.
+
'''Game Engine''':
 +
The core program of the game which reads and executes your scripting commands at run time.
  
Check out [[SQF syntax]] for information about the notation of comments.
+
'''Function''':
 +
See [[Function]]
  
'''Important:''' Don't write down what the code does, but rather what ''you'' want to do with the code. This is not as easy, but maybe the following example explains it a bit better:
+
'''Variables''':
 +
See [[Variables]]
  
Bad comment:
+
'''Operators''':
 +
See [[Operators]]
  
// the variable i gets the value 1
 
i = 1;
 
  
Good comment:
+
== Recommended programs ==
  
// reset the counter to start with 1 again
+
'''Code Edition''' programs can be found on the [[:Category:Community Tools#Code Edition|Community Tools - Code Edition]] page section.
i = 1;
 
  
== Code Execution ==
 
  
how can I execute code? (external files vs. mission editor)
+
== Must-read articles ==
  
=== Mission Editor ===
+
=== Best Practices ===
  
how to execute code in the editor, listing of mission editor fields to start scripts
+
* [[Code Best Practices]]
  
=== External Files ===
+
=== Debugging ===
  
how to execute code in external files, scripts & functions
+
* [[Debugging Techniques]]
 +
* [[:Category:Community_Tools#Debug_Console.2FSystem|Community Tools - Debug Console/System]]
  
== Developing a Script ==
+
=== Optimisation ===
  
script in this case: code in external files (scripts/functions). how to develop a script?
+
* [[Code Optimisation]]
 +
* [[Mission Optimisation]]
  
* Requirements
 
* Concept
 
* Implementation
 
* Test
 
  
usually in your head, for complex scripts on paper and drafts
+
== Useful Links ==
  
=== Requirements ===
+
These links offer a great deal of information about [[Scripting]]:
 
+
* [[:Category:Example Code|Example Code]]
what shall the script do?
 
 
 
=== Concept ===
 
 
 
How shall the script do it?
 
 
 
=== Implementation ===
 
 
 
Writing the code
 
 
 
=== Test ===
 
 
 
Testing the code
 
 
 
== Further Reading ==
 
 
 
If you want to learn more about [[ArmA: Scripting]], read the following articles:
 
 
 
* [[Variables]]
 
* [[Operators]]
 
 
* [[Control Structures]]
 
* [[Control Structures]]
* [[Exception Handling]]
+
* [[Multiplayer Scripting]]
 
+
* [[Exception handling]]
== See also ==
 
 
 
 
* [[Script (File)]]
 
* [[Script (File)]]
 
* [[Function]]
 
* [[Function]]
* [[SQF syntax]]
+
* [[SQS to SQF conversion]]
 +
 
 +
Additionally, the following are more resources for more general learning:
 +
* [[6thSense.eu/EG|6thSense.eu Editing Guide]]
 +
* [http://www.armaholic.com/page.php?id=20465 Fockers Arma 3 Scripting Guide]
 +
* [http://www.armaholic.com/page.php?id=4847 Mr-Murray's Armed Assault Editing Guide - Deluxe Edition]
 +
* [https://www.youtube.com/watch?v=WmEBN-RbK44 Excellent German SQF tutorial (YouTube)]
  
[[Script (File)|Scripts >>]]
 
  
[[Category:ArmA: Scripting|Introduction to Scripting]]
+
[[Category:Scripting Topics]]
 +
[[Category:Operation Flashpoint: Editing]]
 +
[[Category:ArmA: Editing]]
 +
{{GameCategory|arma2|Editing}}
 +
{{GameCategory|arma3|Editing}}
 +
[[Category:Take On Helicopters: Editing]]

Latest revision as of 21:17, 2 August 2020

Introduction

This page should give beginners an overview of how to begin with scripting and where to find most of the information they need in the beginning. Some information might not be complete and can be found on other wiki pages.

During mission editing and addon editing you may come across situations where actions or features you would like to have in your mission or addon cannot be accomplished using the basic (or even the more advanced) capabilities of the mission editor or within config files (in the case of addons). Some examples of this might be really cinematic cutscenes in missions or special animations for an addon.

The solution to this is to take advantage of the game-engine's ability to call on an even more advanced feature known as scripting. Arma's scripting language gives you a more direct control of core game features. With any combination of these commands and functions you can create custom processes that meet the specific needs of your mission or addon.


Before anything

Is your idea necessary?

  • Will players even notice or use what you want to script? Just because you can doesn’t mean you should. Sometimes less is more!

Is it possible to do this in the editor?

  • Eden Editor is an incredibly powerful tool and with it alone one can achive a lot of things, even without writing a single line of SQF.
  • Poorly written scripts are often the reason for poor performance both in singleplayer and multiplayer scenarios.

Can it be scripted using SQF?

  • This might be hard to answer, especially for beginners. Try to get as much information about what you want to do and what commands and functions there are before spending time on writing a script, just to find out it is not possible in the end.


Depending on your answer for these questions, you may want to rethink your approach.

Scripting is not a solution to everything.


Terms

Before getting started, you should understand the meaning of these terms.

Data Types: See Data Types

Algorithm: In mathematics and computer science, an algorithm is an explicit specification of how to solve a class of problems. Algorithms can perform calculation, data processing and automated reasoning tasks.

Interpreter: Reads your code from a script file and translates it into instructions for you to achieve your desired outcome/effect in the game.

Control Structures: See Control Structures

Syntax:

Script: When speaking about a script, we usually mean a .sqs or .sqf file.

Game Engine: The core program of the game which reads and executes your scripting commands at run time.

Function: See Function

Variables: See Variables

Operators: See Operators


Recommended programs

Code Edition programs can be found on the Community Tools - Code Edition page section.


Must-read articles

Best Practices

Debugging

Optimisation


Useful Links

These links offer a great deal of information about Scripting:

Additionally, the following are more resources for more general learning: