Ceeeb/Sandbox\ArmA: Scripting - Getting Started – User

From Bohemia Interactive Community
Jump to navigation Jump to search
(minor lexical corrections and a few additions)
Line 16: Line 16:
*'''Private Kouba''': I don't know where Petrovice is, sir.
*'''Private Kouba''': I don't know where Petrovice is, sir.


Now we have a problem. Kouba only knows how to get to Lipany and Honka only knows how to get to Petrovice. Our solders are new recruits and are really quite stupid. They can only take simple orders, one order at a time.  They can get in and out of vehicles, drive, and load and unload weapons and ammo. The commander must plan this sequence of orders and make provisions for obstacles that may arise.
Now we have a problem. Kouba only knows how to get to Lipany and Honka only knows how to get to Petrovice. Our soldiers are new recruits and are really quite stupid. They can only take simple orders, one order at a time.  They can get in and out of vehicles, drive, and load and unload weapons and ammo. The commander must plan this sequence of orders and make provisions for obstacles that may arise.


1. Destination is Petrovice
# Destination is Petrovice
2. Get in vehicle
# Get in vehicle
3. If driver does not know the way to Destination, swap driver and passenger
# If driver does not know the way to Destination, swap driver and passenger
4. Drive to Destination
# Drive to the destination
5. Get out of vehicle
# Get out of vehicle
6. Load vehicle
# Load vehicle
7. Destination is Lipany
# Destination is Lipany
8. Get in vehicle
# Get in vehicle
9. If driver does not know the way to Destination, swap driver and passenger
# If driver does not know the way to Destination, swap driver and passenger
10. Drive to Destination
# Drive to Destination
11. Get out of vehicle
# Get out of vehicle
12. Unload vehicle
# Unload vehicle


===Interpreter===
===Interpreter===


If you have an algorithm, you need something that can execute it. We have a computer game, Armed Assault, which is able to do this; commanders have solders.
If you have an algorithm, you need something that can execute it. We have a computer game, Armed Assault, which is able to do this; commanders have soldiers.


===Programming language===
===Programming language===
Line 41: Line 41:
===Source code===
===Source code===


Source code is algorithm written in any programming language
Source code is algorithm written in any programming language.


===Syntax===
===Syntax===


'''Syntax''' is made up of commands and parameters, sometimes just the command is required as in (need example) other times the '''syntax''' is made up of one or more parameters. Each command has it's own reference in the [[Scripting]] section of the wiki. In each case the command + its parameters are listed with examples on how that particular command works.
'''Syntax''' is made up of commands and parameters, sometimes just the command is required as in [[exit]], other times the '''syntax''' is made up of one or more parameters. Each command has it's own reference in the [[Scripting]] section of the wiki. In each case the command + its parameters are listed with examples on how that particular command works.


  '''[[if]]'''(PrivateHonka == TheMostCleverSolderInTheWorld) [[then]] {
  '''[[if]]'''(PrivateHonka == TheMostCleverSolderInTheWorld) [[then]] {
     IAmChineeseGodOfHumour = true
     IAmChineeseGodOfHumour = true;
  }
  };
 
Be aware though that Armed Assault features two similar scripting grammars: [[SQF]] and [[SQS]].


===Interpreting works===  
===Interpreting works===  


The '''Armed Assault''' engine reads your code from script files and translates those instructions for your to achieve your desired out come/effect in the game.
The '''Armed Assault''' engine reads your code from script files and translates those instructions for you to achieve your desired outcome/effect in the game.


===Let's start===
===Let's start===


Every script consist of commands (see category Scripting Commands) and [[Control Structures|program flow]] statements (they are implemented as commands in Armed Assault, but it isn't relevant for now). The most useful command in your first script is [[titleText]]. It can write to the player's screen any text you want.
Every script consist of commands (see [[:Category:Scripting Commands|category Scripting Commands]]) and [[Control Structures|program flow]] statements (they are implemented as commands in Armed Assault, but it isn't relevant for now). The most useful command in your first script is [[titleText]]. It can write any text you want to the player's screen.


  [[titleText]]["Good morning, captain", "PLAIN DOWN"]
  [[titleText]]["Good morning, captain", "PLAIN DOWN"];


It's a typical way to run commands. Behind the name of the command the parameters follow (but it depends on the command (see [[:Category:Scripting Commands]]). Every command can only have one parameter before it's name and/or one after (more arguments can be given with arrays which count as one parameter). Parameters can be of various [[:Category:Types|Data types]]. In this case it's an [[Array]] - a list of other data types. It can contain 0 - 4096? values. The first value is a [[String]] representing the text to be displayed and the second, in this case, says in what position on the screen the text will be displayed. There can be a third value: a [[Number]] which says how long the text needs to fade in. If this value is not entered, its default value (1) is used.
It's a typical way to run commands. Behind the name of the command the parameters follow (but it depends on the command (see [[:Category:Scripting Commands]]). Every command can only have one parameter before it's name and/or one after (more arguments can be given with arrays which count as one parameter). Parameters can be of various [[:Category:Types|Data types]]. In this case it's an [[Array]] - a list of other data types. It can contain 0 - 4096? values. The first value is a [[String]] representing the text to be displayed and the second, in this case, says in what position on the screen the text will be displayed. There can be a third value: a [[Number]] which says how long the text needs to fade in. If this value is not entered, its default value (1) is used.


  [[titleText]]["Good morning, captain", "PLAIN DOWN", 5]
  [[titleText]]["Good morning, captain", "PLAIN DOWN", 5];


Scripts which are called [[function]]s) are stored in .SQF files the mission folder, or in .SQSs files and then called only scripts.
Scripts which are called [[function]]s) are stored in .SQF files the mission folder, or in .SQSs files and then called only scripts.


If you want to try our 'script', create a mission in the mission editor, save it as testingmission, open Notepad, write "[[titleText]]["Good morning, captain", "PLAIN DOWN"]" (without the outer "") and save it as hello.sqf to gamefolder/user/yourname/missions/testingmission. Then add solder in mission editor and to his initialization field type "execVM "hello.sqf"" (without the outer quotes). When you run this mission, you should see output of your first script. Well done, soldier! (If you are confused from this quantum of informations, don't panic, more continuously explanation follows.)
If you want to try our 'script', create a mission in the mission editor, save it as ''testingmission'', open a text editor (eg. Notepad), write "[[titleText]]["Good morning, captain", "PLAIN DOWN"];" (without the outer "") and save it as hello.sqf to gamefolder/user/yourname/missions/testingmission. Then add solder in mission editor and to his initialization field type "execVM "hello.sqf"" (without the outer quotes). When you run this mission, you should see output of your first script. Well done, soldier! (If you are confused from this quantum of informations, don't panic, more continuously explanation follows.)


== Variables ==
== Variables ==

Revision as of 02:31, 12 May 2007

Introduction

Scripts are a essential part of mission making. They allow you to create amazing cutscenes, create effects and customize almost every aspect of your mission. Some diverse examples of what could be scripted are: a simulation of artillery fire, a poisonous gas cloud, or a money system for purchasing equipment.

Algorithm

Your first task in writing scripts is to decide what sequence of steps is needed to solve a particular problem. This sequence is what would be called an algorithm.

For example, if you wanted to transport weapons from Petrovice to Lipany, you would (as commander) give these orders:

  • Commander: Private Honka, private Kouba, come here!
  • Commander: Private Kouba, get in Ural as driver!
  • Commander: Private Honka, get in Ural!
  • Commander: Private Kouba, drive to Petrovice and load Ural!
  • Private Kouba: I don't know where Petrovice is, sir.

Now we have a problem. Kouba only knows how to get to Lipany and Honka only knows how to get to Petrovice. Our soldiers are new recruits and are really quite stupid. They can only take simple orders, one order at a time. They can get in and out of vehicles, drive, and load and unload weapons and ammo. The commander must plan this sequence of orders and make provisions for obstacles that may arise.

  1. Destination is Petrovice
  2. Get in vehicle
  3. If driver does not know the way to Destination, swap driver and passenger
  4. Drive to the destination
  5. Get out of vehicle
  6. Load vehicle
  7. Destination is Lipany
  8. Get in vehicle
  9. If driver does not know the way to Destination, swap driver and passenger
  10. Drive to Destination
  11. Get out of vehicle
  12. Unload vehicle

Interpreter

If you have an algorithm, you need something that can execute it. We have a computer game, Armed Assault, which is able to do this; commanders have soldiers.

Programming language

It's way how to write our algorithm for Armed Assault. ArmA scripts are a sequence of 'orders' describing how to do it.

Source code

Source code is algorithm written in any programming language.

Syntax

Syntax is made up of commands and parameters, sometimes just the command is required as in exit, other times the syntax is made up of one or more parameters. Each command has it's own reference in the Scripting section of the wiki. In each case the command + its parameters are listed with examples on how that particular command works.

if(PrivateHonka == TheMostCleverSolderInTheWorld) then {
    IAmChineeseGodOfHumour = true;
};

Be aware though that Armed Assault features two similar scripting grammars: SQF and SQS.

Interpreting works

The Armed Assault engine reads your code from script files and translates those instructions for you to achieve your desired outcome/effect in the game.

Let's start

Every script consist of commands (see category Scripting Commands) and program flow statements (they are implemented as commands in Armed Assault, but it isn't relevant for now). The most useful command in your first script is titleText. It can write any text you want to the player's screen.

titleText["Good morning, captain", "PLAIN DOWN"];

It's a typical way to run commands. Behind the name of the command the parameters follow (but it depends on the command (see Category:Scripting Commands). Every command can only have one parameter before it's name and/or one after (more arguments can be given with arrays which count as one parameter). Parameters can be of various Data types. In this case it's an Array - a list of other data types. It can contain 0 - 4096? values. The first value is a String representing the text to be displayed and the second, in this case, says in what position on the screen the text will be displayed. There can be a third value: a Number which says how long the text needs to fade in. If this value is not entered, its default value (1) is used.

titleText["Good morning, captain", "PLAIN DOWN", 5];

Scripts which are called functions) are stored in .SQF files the mission folder, or in .SQSs files and then called only scripts.

If you want to try our 'script', create a mission in the mission editor, save it as testingmission, open a text editor (eg. Notepad), write "titleText["Good morning, captain", "PLAIN DOWN"];" (without the outer "") and save it as hello.sqf to gamefolder/user/yourname/missions/testingmission. Then add solder in mission editor and to his initialization field type "execVM "hello.sqf"" (without the outer quotes). When you run this mission, you should see output of your first script. Well done, soldier! (If you are confused from this quantum of informations, don't panic, more continuously explanation follows.)

Variables

See Variables

Statements and operators

See Operators