arma:scripting
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
arma:scripting [2008/04/30 15:03] – added more script background info snakeman | arma:scripting [2008/04/30 15:24] – added bunch of info to the scripting. snakeman | ||
---|---|---|---|
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. | ||
+ | |||
====== Overview ====== | ====== Overview ====== | ||
- | ArmA has “” | + | How do you run SQF script? |
+ | |||
+ | argument execVM filename | ||
+ | |||
+ | Example: | ||
+ | < | ||
+ | var = [player] execVM " | ||
+ | </ | ||
+ | |||
+ | Argument is passed to the script as local variable _this. | ||
+ | The Script is first searched for in the mission folder, then in the campaign scripts folder and finally in the global scripts folder. | ||
+ | |||
+ | ArmA has "" | ||
< | < | ||
Line 21: | Line 34: | ||
DoSomething5; | DoSomething5; | ||
}; | }; | ||
- | } foreach | + | } forEach |
</ | </ | ||
Line 29: | Line 42: | ||
{if (condition) then {DoSomething1; | {if (condition) then {DoSomething1; | ||
</ | </ | ||
+ | |||
+ | ====== Comments ====== | ||
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. | ||
Line 42: | Line 57: | ||
< | < | ||
/* | /* | ||
- | | + | Comment line 1 |
- | Comment line 2 | + | Comment line 2 |
- | Comment line 3 | + | Comment line 3 |
- | Comment line 4 | + | Comment line 4 |
- | Comment line 5 | + | Comment line 5 |
- | Comment line 6 | + | Comment line 6 |
*/ | */ | ||
</ | </ | ||
Line 53: | Line 68: | ||
Quotes are no longer a valid substitute for braces. | Quotes are no longer a valid substitute for braces. | ||
- | Some SQF things | + | ====== |
+ | |||
+ | Some misc SQF things here ;) | ||
< | < | ||
Line 64: | Line 81: | ||
</ | </ | ||
+ | And | ||
+ | < | ||
+ | myFunction1 = compile loadFile " | ||
+ | myFunction2 = compile preprocessFile " | ||
+ | |||
+ | call myFunction1; | ||
+ | [1, 2] call myFunction2; | ||
+ | </ | ||
+ | |||
+ | Return value? | ||
+ | |||
+ | < | ||
+ | value = call compile preprocessFile " | ||
+ | // value is now RETURN_VALUE | ||
+ | |||
+ | call compile preprocessFile " | ||
+ | // valid, but RETURN_VALUE is not saved anywhere | ||
+ | </ | ||
+ | |||
+ | ====== Private ====== | ||
+ | |||
+ | Using the private list. | ||
+ | |||
+ | < | ||
+ | private [" | ||
+ | </ | ||
+ | Is to make the _local variables really a private ones in the SQF script. | ||
+ | |||
+ | ====== Exit while loop ====== | ||
+ | |||
+ | < | ||
+ | if (condition) exitWith {Code} | ||
+ | |||
+ | if (_x > 5) exitWith {echo "_x is too big"; _x} | ||
+ | </ | ||
+ | |||
+ | and | ||
+ | |||
+ | < | ||
+ | for " | ||
+ | { | ||
+ | player sideChat format [" | ||
+ | if (_j == 5) exitWith {player sideChat "5 is enough" | ||
+ | }; | ||
+ | player sideChat " | ||
+ | </ | ||
+ | |||
+ | ====== Switch ====== | ||
+ | |||
+ | Switch is quite nice option to check many conditions at once. | ||
+ | |||
+ | Example 1 | ||
+ | < | ||
+ | switch (_a) do | ||
+ | { | ||
+ | case 1: | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | case 2: | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | default | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | ;} | ||
+ | </ | ||
+ | |||
+ | Example 2 | ||
+ | < | ||
+ | switch (_a) do | ||
+ | { | ||
+ | case true: | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | case false: | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | default | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Example 3 | ||
+ | < | ||
+ | switch (_a) do | ||
+ | { | ||
+ | case " | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | case " | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | default | ||
+ | { | ||
+ | hint " | ||
+ | }; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ====== Script to nil ====== | ||
+ | |||
+ | When you have script like this | ||
+ | < | ||
+ | MyScript = compile preProcessFile " | ||
+ | </ | ||
+ | |||
+ | When you want to unload the script, set MyScript equal to nil. | ||
+ | |||
+ | < | ||
+ | MyScript = nil; | ||
+ | </ | ||
+ | |||
+ | ====== Dynamic Variables ====== | ||
+ | |||
+ | Dynamic variables are very cool, sometimes on those random/ | ||
+ | |||
+ | < | ||
+ | _MyVariable = 20; | ||
+ | _MyVariableContent = " | ||
+ | call compile format[" | ||
+ | </ | ||
+ | |||
+ | This would create: MyDynamic_20 variable with content: " | ||
+ | |||
+ | Another example | ||
+ | < | ||
+ | _name = format [" | ||
+ | call compile format ["%1 = createTrigger [....]", | ||
+ | </ | ||
====== Misc PMC Example Scripts ====== | ====== Misc PMC Example Scripts ====== | ||
Place random vehicles + some units on all found **pmc_** gamelogics script, [[arma: | Place random vehicles + some units on all found **pmc_** gamelogics script, [[arma: |
arma/scripting.txt · Last modified: 2024/08/01 10:46 by snakeman