Code: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(fixed typo)
No edit summary
Line 1: Line 1:
Values of type '''Code''' represent some functionality or calculation. Often is it passed as an argument into some scripting commands which will execute it straight away, or at some later time, e.g. [[call]], [[addEventHandler]] or [[onMapSingleClick]].
'''Code''' represents data consisting of commands and their parameters. The contents of [[sqf]] and [[sqs]] files, for example are 'Code'. In turn, it can also be the case that one of the scripting commands gets passed further scripting commands, e.g. [[for]] {Code} [[do]] {Code}; unit [[addEventHandler]] [Event Handler type, {Code}]; [[onMapSingleClick]] "Code".


The text body that makes up '''Code''' are also scripting commands.
Code literals are usually represented by enclosing text into curly braces: '{' and '}'. Any such code is precompiled by the script engine. Sometimes it may become necessary to first read in certain commands as String. In order to convert code from data type String into data type Code, the command [[compile]] can be used. See [[Code vs. Strings]] for more information on code data typing.
 
'''Code''' literals are represented by enclosing text into curly braces. '''{''' code.... '''}''' Any such code is precompiled by the script engine. Code values may also originate as a text, which can be converted to code using [[compile]] command.
 
[[ArmA|Armed Assault]] formalised this 'convention' by creating a Code '''Type'''. In previous versions it was a prefered style to write such strings in curled braces, but it was also possible to write them in quotation marks (exactly like [[String]]s). ArmA commands that are marked as requiring '''Code''' must be presented with curled braces. Resistance / Cold War crisis commands using a '''Code''' style paramater should ''also'' used curled brace as a good writing style that was adopted very early on by most mission makers.


==Examples==
==Examples==

Revision as of 13:58, 18 January 2010

Code represents data consisting of commands and their parameters. The contents of sqf and sqs files, for example are 'Code'. In turn, it can also be the case that one of the scripting commands gets passed further scripting commands, e.g. for {Code} do {Code}; unit addEventHandler [Event Handler type, {Code}]; onMapSingleClick "Code".

Code literals are usually represented by enclosing text into curly braces: '{' and '}'. Any such code is precompiled by the script engine. Sometimes it may become necessary to first read in certain commands as String. In order to convert code from data type String into data type Code, the command compile can be used. See Code vs. Strings for more information on code data typing.

Examples

{_x setDamage 1} forEach ArrayToKill