User Tools

Site Tools


arma:scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
arma:scripting [2008-04-30 15:24]
snakeman added bunch of info to the scripting.
arma:scripting [2009-04-16 11:52]
snakeman added more scripting stuff.
Line 6: Line 6:
  
 In a nutshell you never ever should create ArmA SQS content anymore, always create only SQF scripts. In a nutshell you never ever should create ArmA SQS content anymore, always create only SQF scripts.
 +
 +
 +====== Introduction to ArmA scripting ======
 +
 +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-engines ability to call on an even more advanced feature known as scripting. Armed Assault'​s scripting language gives you more direct control of core game commands. With any combination of these scripting commands you can then create custom processes that meet the specific needs of your mission or addon. ​
 +
 +
 +===== Terms =====
 +
 +Before getting started, you should understand the meaning of some of these terms.
 +
 +**Script**
 +
 +When speaking about a script, it is generally considered a .sqs file, the same can be said for functions, since functions are a kind of script as well, the file ends with a .sqf. Both file types can be edited as a plain text file. 
 +
 +**Game Engine**
 +
 +The core program of the game which reads and executes your scripting commands at run time. 
  
  
Line 15: Line 35:
  
 Example: Example:
-<​code>​+<​code ​cpp>
 var = [player] execVM "​test.sqf";​ var = [player] execVM "​test.sqf";​
 </​code>​ </​code>​
Line 24: Line 44:
 ArmA has ""​ quotes for STRINGS only and {} curled braces for CODE only. Script commands doesn’t have to be in one line now with the curled braces. Command lines always end with ; instead of a ; *or* carriage return. So you can format code to be more readable ArmA has ""​ quotes for STRINGS only and {} curled braces for CODE only. Script commands doesn’t have to be in one line now with the curled braces. Command lines always end with ; instead of a ; *or* carriage return. So you can format code to be more readable
  
-<​code>​+<​code ​cpp>
 { {
     if (condition) then     if (condition) then
Line 39: Line 59:
 Instead of the terrible ofp classic Instead of the terrible ofp classic
  
-<​code>​+<​code ​cpp>
 {if (condition) then {DoSomething1;​ DoSomething2;​ DoSomething3;​ DoSomething4;​ DoSomething5;​};​} foreach array; {if (condition) then {DoSomething1;​ DoSomething2;​ DoSomething3;​ DoSomething4;​ DoSomething5;​};​} foreach array;
 </​code>​ </​code>​
Line 47: Line 67:
 Comments are no longer the same character as the end of command character. Comments are no longer the same character as the end of command character.
  
-<​code>​+<​code ​cpp>
 // my comment // my comment
 instead of instead of
Line 55: Line 75:
 You can use block comments now. You can use block comments now.
  
-<​code>​+<​code ​cpp>
 /* /*
 Comment line 1 Comment line 1
Line 72: Line 92:
 Some misc SQF things here ;) Some misc SQF things here ;)
  
-<​code>​+<​code ​cpp>
 _resultArray = [0,""​];​ _resultArray = [0,""​];​
 _handle = [_resultArray] execVM "​resultScript.sqf";​ _handle = [_resultArray] execVM "​resultScript.sqf";​
Line 82: Line 102:
  
 And And
-<​code>​+<​code ​cpp>
 myFunction1 = compile loadFile "​myFunction1.sqf";​ myFunction1 = compile loadFile "​myFunction1.sqf";​
 myFunction2 = compile preprocessFile "​myFunction2.sqf";​ myFunction2 = compile preprocessFile "​myFunction2.sqf";​
Line 92: Line 112:
 Return value? Return value?
  
-<​code>​+<​code ​cpp>
 value = call compile preprocessFile "​return.sqf";​ value = call compile preprocessFile "​return.sqf";​
 // value is now RETURN_VALUE // value is now RETURN_VALUE
Line 104: Line 124:
 Using the private list. Using the private list.
  
-<​code>​ +<​code ​cpp
-private ["​_t","​_p","​_yea"​];​+private ["​_t",​ "​_p",​ "​_yea"​];​
 </​code>​ </​code>​
 Is to make the _local variables really a private ones in the SQF script. Is to make the _local variables really a private ones in the SQF script.
Line 111: Line 131:
 ====== Exit while loop ====== ====== Exit while loop ======
  
-<​code>​+<​code ​cpp>
 if (condition) exitWith {Code} if (condition) exitWith {Code}
  
Line 117: Line 137:
 </​code>​ </​code>​
  
-and+And
  
-<​code>​+<​code ​cpp>
 for "​_j"​ from 1 to 10 do for "​_j"​ from 1 to 10 do
 { {
Line 133: Line 153:
  
 Example 1 Example 1
-<​code>​+<​code ​cpp>
 switch (_a) do switch (_a) do
 { {
Line 152: Line 172:
  
 Example 2 Example 2
-<​code>​+<​code ​cpp>
 switch (_a) do switch (_a) do
 { {
Line 171: Line 191:
  
 Example 3 Example 3
-<​code>​+<​code ​cpp>
 switch (_a) do switch (_a) do
 { {
Line 192: Line 212:
  
 When you have script like this When you have script like this
-<​code>​+<​code ​cpp>
 MyScript = compile preProcessFile "​myScript.sqf";​ MyScript = compile preProcessFile "​myScript.sqf";​
 </​code>​ </​code>​
Line 198: Line 218:
 When you want to unload the script, set MyScript equal to nil. When you want to unload the script, set MyScript equal to nil.
  
-<​code>​+<​code ​cpp>
 MyScript = nil; MyScript = nil;
 </​code>​ </​code>​
Line 204: Line 224:
 ====== Dynamic Variables ====== ====== Dynamic Variables ======
  
-Dynamic variables are very cool, sometimes on those random/comples ​missions you want to make variables later in the mission, which you cannot specify at mission start (hardcode).+Dynamic variables are very cool, sometimes on those random / complex ​missions you want to make variables later in the mission, which you cannot specify at mission start (hardcoded).
  
-<​code>​+<​code ​cpp>
 _MyVariable = 20; _MyVariable = 20;
 _MyVariableContent = "​MyContent";​ _MyVariableContent = "​MyContent";​
Line 215: Line 235:
  
 Another example Another example
-<​code>​+<​code ​cpp>
 _name = format ["​mytrigger%1",​ triggerIndex];​ _name = format ["​mytrigger%1",​ triggerIndex];​
 call compile format ["%1 = createTrigger [....]",​ _name]; call compile format ["%1 = createTrigger [....]",​ _name];
Line 223: Line 243:
  
 Place random vehicles + some units on all found **pmc_** gamelogics script, [[arma:​scripting:​pmc_logic1|here]]. Place random vehicles + some units on all found **pmc_** gamelogics script, [[arma:​scripting:​pmc_logic1|here]].
 +
 +
 +====== Running Scripts "​Live"​ ======
 +
 +When you start your mission in mission editor, you can go and edit your scripts and then they are called the next time, they will be reloaded at the same time so your edits to them will be usable.
 +
 +This is very nice feature to have, just run ArmA in window mode as you should always do when mission editing, then edit away and for example keep a "​runme.sqf"​ script in the dir executed from radio alpha (or action menu) repeatedly, then you can edit the runme.sqf and add any additional script there what you want to run.
 +
 +You can now run a long mission and always bring new scripts into the play and so on. Imagine how many times have you play tested a mission and had to wrote down notes that "in this and that part you need to add XYZ", but now... you can just write a quick script (or use existing one) and add that to the runme.sqf and just call it up... script is run and you can proceed with the mission. Great.
arma/scripting.txt · Last modified: 2011-08-15 09:30 by snakeman