Functions Library – Arma 3
m (→See Also) |
Lou Montana (talk | contribs) (Some wiki formatting) |
||
Line 2: | Line 2: | ||
{{arma3}}'s '''Functions Library''' is the way to declare mission, campaign or addon's [[Function]]s. The main difference from older [[:Category:Functions Library|Function Libraries]] is that it runs automatically and does not require a Functions module. | {{arma3}}'s '''Functions Library''' is the way to declare mission, campaign or addon's [[Function]]s. The main difference from older [[:Category:Functions Library|Function Libraries]] is that it runs automatically and does not require a Functions module. | ||
The advantages of using the Functions Library over e.g [[execVM]] an [[SQF Syntax|SQF]] file are as follow: | The advantages of using the Functions Library over e.g [[execVM]] an [[SQF Syntax|SQF]] file are as follow: | ||
# '''Automatic compilation upon mission start''' into a global variable - no need to remember direct paths to files. | # '''Automatic compilation upon mission start''' into a global variable - no need to remember direct paths to files. | ||
Line 11: | Line 9: | ||
# '''Optional immediate execution upon mission start''', without need for manual call | # '''Optional immediate execution upon mission start''', without need for manual call | ||
# '''Potential performance improvements''' | # '''Potential performance improvements''' | ||
Line 28: | Line 25: | ||
{{Feature| | {{Feature|informative|The root directory (noted as '''<ROOT>''' on this page) is the origin from which the game will try to load function files. It depends on <tt>CfgFunctions</tt>' location: | ||
* if [[Description.ext]], ''' | * if [[Description.ext]], '''<ROOT>''' means the [[Mission Editor: External#Mission Folder|mission' root]] directory | ||
* if [[Campaign Description.ext]], ''' | * if [[Campaign Description.ext]], '''<ROOT>''' means the campaign's root directory | ||
* if in config, ''' | * if in config, '''<ROOT>''' means the '''game'''<nowiki/>'s root directory. The addon path needs to be set manually. | ||
}} | }} | ||
Line 40: | Line 37: | ||
class {{Color|purple|TAG}} | class {{Color|purple|TAG}} | ||
{ | { | ||
class {{Color| | class {{Color|darkorange|Category}} | ||
{ | { | ||
class {{Color|teal|functionName}} {}; | class {{Color|teal|functionName}} {}; | ||
Line 48: | Line 45: | ||
* The function's name will be '''{{Color|purple|TAG}}'''_fnc_'''{{Color|teal|functionName}}''' | * The function's name will be '''{{Color|purple|TAG}}'''_fnc_'''{{Color|teal|functionName}}''' | ||
* The function will be loaded: | * The function will be loaded: | ||
** from config: <tt>''' | ** from config: <tt>'''<ROOT>'''\{{Color|darkorange|Category}}\'''fn_'''{{Color|teal|functionName}}'''.sqf'''</tt> | ||
** from description.ext: <tt>''' | ** from description.ext: <tt>'''<ROOT>'''\'''Functions'''\{{Color|darkorange|Category}}\'''fn_'''{{Color|teal|functionName}}'''.sqf'''</tt> | ||
{{Feature|informative|'''config.cpp only''': Anywhere outside of running mission, refer to the functions stored in [[uiNamespace]]. | {{Feature|informative|'''config.cpp only''': Anywhere outside of running mission, refer to the functions stored in [[uiNamespace]]. e.g: | ||
<code>''arguments'' [[call]] ([[uiNamespace]] [[getVariable]] ''"functionName"'');</code>}} | |||
=== Config Levels === | === Config Levels === | ||
Line 73: | Line 70: | ||
class TAG_WeaponManagement | class TAG_WeaponManagement | ||
{ | { | ||
tag = {{Color|purple|"TAG"}}; {{cc|the function will be named '''{{Color|purple|TAG}}_fnc_myOtherFunction'''}} | '''tag''' = {{Color|purple|"TAG"}}; {{cc|the function will be named '''{{Color|purple|TAG}}_fnc_myOtherFunction'''}} | ||
class Category | class Category | ||
{ | { | ||
Line 83: | Line 80: | ||
===== Attributes ===== | ===== Attributes ===== | ||
====== tag ====== | ====== tag ====== | ||
The <tt>tag</tt> attribute can override the config {{Color|green|tag}} set differently. | |||
=== Category === | === Category === | ||
Line 92: | Line 89: | ||
class TAG | class TAG | ||
{ | { | ||
class {{Color| | class {{Color|darkorange|Category}} | ||
{ | { | ||
class myFunction {}; | class myFunction {}; | ||
}; | }; | ||
class | class OtherCategory | ||
{ | { | ||
'''file''' = "My\Category\Path"; | '''file''' = "{{Color|darkorange|My}}\{{Color|darkorange|Category}}\{{Color|darkorange|Path}}"; | ||
class myFunction {}; {{cc|file path will be | class myFunction {}; {{cc|file path will be '''<ROOT>'''\{{Color|darkorange|My}}\{{Color|darkorange|Category}}\{{Color|darkorange|Path}}\fn_myFunction.sqf";}} | ||
}; | }; | ||
class | class DataCategory | ||
{ | { | ||
'''requiredAddons[]''' = { "A3_Data_F" }; {{cc|Optional requirements of [[CfgPatches]] classes. If some addons are missing, category functions will not be compiled.}} | '''requiredAddons[]''' = {{Color|darkorange|{ "A3_Data_F" }<nowiki/>}}; {{cc|Optional requirements of [[CfgPatches]] classes. If some addons are missing, category functions will not be compiled.}} | ||
class myDataFunction {}; | class myDataFunction {}; | ||
}; | }; | ||
Line 118: | Line 115: | ||
====== requiredAddons ====== | ====== requiredAddons ====== | ||
The category can skip loading if a required addon is missing by setting its dependency with the <tt>requiredAddons</tt> attribute. | The category can skip loading if a required addon is missing by setting its dependency with the <tt>requiredAddons</tt> attribute. | ||
=== Function === | === Function === | ||
Line 143: | Line 135: | ||
{ | { | ||
file = "Path\To\Category"; | file = "Path\To\Category"; | ||
class | class myFunction | ||
{ | { | ||
'''file''' = "My\Function\Filepath.sqf"; {{cc|file path will be | '''file''' = "{{Color|teal|My}}\{{Color|teal|Function}}\{{Color|teal|Filepath.sqf}}"; {{cc|file path will be '''<ROOT>'''\{{Color|teal|My}}\{{Color|teal|Function}}\{{Color|teal|Filepath.sqf}}", ignoring "Path\To\Category"}} | ||
}; | }; | ||
class {{Color|teal| | class {{Color|teal|myFSMFunction}} | ||
{ | { | ||
preInit = 1; | '''preInit''' = 1; | ||
postInit = 1; | '''postInit''' = 1; | ||
ext = ".fsm"; | '''ext''' = ".fsm"; | ||
preStart = 1; | '''preStart''' = 1; | ||
recompile = 1; | '''recompile''' = 1; | ||
}; | }; | ||
}; | }; | ||
Line 162: | Line 154: | ||
===== Attributes ===== | ===== Attributes ===== | ||
{| class="wikitable" | {| class="wikitable" | ||
| | ! rowspan="2" | Attribute | ||
! | ! rowspan="2" | Description | ||
! Description | ! colspan="2" | Available in | ||
|- style="font-size: 0.9em" | |||
! [[Description.ext]] | |||
! [[config.cpp]] | |||
|- | |- | ||
| file | | file | ||
| the <tt>file</tt> attribute can be used to manually set the file path. | | the <tt>file</tt> attribute can be used to manually set the file path. | ||
{{Feature|important|The '''file''' entry '''overrides''' Category's set path and ignores it entirely (they are not merged).}} | {{Feature|important|The '''file''' entry '''overrides''' Category's set path and ignores it entirely (they are not merged).}} | ||
| style="text-align: center" | {{Icon|checked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|- | |- | ||
| preInit | | preInit | ||
| the <tt>preInit</tt> attribute (formerly known as "forced") can be set to 1 to call the function upon mission start, before objects are initialized.<br>Passed arguments are {{ic|["preInit"]}}. The function is run in an '''[[Scheduler#Unscheduled Environment|unscheduled environment]]'''. | | the <tt>preInit</tt> attribute (formerly known as "forced") can be set to 1 to call the function upon mission start, before objects are initialized.<br>Passed arguments are {{ic|["preInit"]}}. The function is run in an '''[[Scheduler#Unscheduled Environment|unscheduled environment]]'''. | ||
| style="text-align: center" | {{Icon|checked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|- | |- | ||
| postInit | | postInit | ||
| the <tt>postInit</tt> attribute can be set to 1 to call the function upon mission start, after objects are initialized.<br>Passed arguments are {{ic|["postInit", [[didJIP]]]}}. The function is run in a '''[[Scheduler#Scheduled Environment|scheduled environment]]''' so suspension is allowed, but '''any long term suspension will halt the mission loading until suspension is done'''. | | the <tt>postInit</tt> attribute can be set to 1 to call the function upon mission start, after objects are initialized.<br>Passed arguments are {{ic|["postInit", [[didJIP]]]}}. The function is run in a '''[[Scheduler#Scheduled Environment|scheduled environment]]''' so suspension is allowed, but '''any long term suspension will halt the mission loading until suspension is done'''. | ||
| style="text-align: center" | {{Icon|checked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|- | |- | ||
| ext | | ext | ||
| the <tt>ext</tt> attribute can be used to set function file's type; it can be | | the <tt>ext</tt> attribute can be used to set function file's type; it can be | ||
* ".sqf" (default) | |||
* ".fsm" (see [[FSM]]) | |||
| style="text-align: center" | {{Icon|checked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|- | |||
| preStart | |||
| the <tt>preStart</tt> attribute can be set to 1 to call the function upon game start, before title screen, but after all addons are loaded. | |||
| style="text-align: center" | {{Icon|unchecked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|- | |||
| recompile | |||
| the <tt>recompile</tt> attribute can be set to 1 to recompile the function upon mission start (functions in [[Description.ext]] are always compiled upon mission (re)start) | |||
| style="text-align: center" | {{Icon|unchecked}} | |||
| style="text-align: center" | {{Icon|checked}} | |||
|} | |} | ||
Line 187: | Line 200: | ||
* Server admins might blacklist the whole addon if they find out the function is used for hacking | * Server admins might blacklist the whole addon if they find out the function is used for hacking | ||
}} | }} | ||
Line 206: | Line 206: | ||
* [[Initialization Order]] | * [[Initialization Order]] | ||
* [[Arma 3: Functions Viewer]] | * [[Arma 3: Functions Viewer]] | ||
* [[:Category:Arma 3: Functions|Arma 3 | * [[:Category:Arma 3: Functions|Arma 3 Functions]] | ||
* [[Arma 3: Writing a Function]] | * [[Arma 3: Writing a Function]] | ||
{{GameCategory|arma3|Editing}} | {{GameCategory|arma3|Editing}} | ||
[[Category: Functions Library]] | [[Category: Functions Library]] |
Revision as of 00:21, 5 August 2021
Arma 3's Functions Library is the way to declare mission, campaign or addon's Functions. The main difference from older Function Libraries is that it runs automatically and does not require a Functions module.
The advantages of using the Functions Library over e.g execVM an SQF file are as follow:
- Automatic compilation upon mission start into a global variable - no need to remember direct paths to files.
- Anti-hack protection using compileFinal (see Recompiling)
- Listing in the Functions Viewer
- Advanced debugging options
- Optional immediate execution upon mission start, without need for manual call
- Potential performance improvements
Function Declaration
Functions are configured within the CfgFunctions class.
Mission and campaign specific functions can be configured in Description.ext/Campaign Description.ext, while addon functions are defined in Config.cpp. Configuration structure is the same in both cases.
See a basic example config:
class CfgFunctions { class TAG { class Category { class functionName {}; }; }; };
- The function's name will be TAG_fnc_functionName
- The function will be loaded:
- from config: <ROOT>\Category\fn_functionName.sqf
- from description.ext: <ROOT>\Functions\Category\fn_functionName.sqf
Config Levels
A CfgFunctions config is made of three levels: Tag, Category, and Function.
Tag
To prevent duplicates, every author must create a subclass with a unique tag and create functions under it. The tag name will be used when composing a function name (e.g BIS_fnc_spawnGroup).
class CfgFunctions { class TAG { class Category { class myFunction {}; }; }; class TAG_WeaponManagement { tag = "TAG"; // the function will be named TAG_fnc_myOtherFunction class Category { class myOtherFunction {}; }; }; };
Attributes
tag
The tag attribute can override the config tag set differently.
Category
The category name changes the function's category in the Functions Viewer. It does not change the function's name, only the loading path.
class CfgFunctions { class TAG { class Category { class myFunction {}; }; class OtherCategory { file = "My\Category\Path"; class myFunction {}; // file path will be <ROOT>\My\Category\Path\fn_myFunction.sqf"; }; class DataCategory { requiredAddons[] = { "A3_Data_F" }; // Optional requirements of CfgPatches classes. If some addons are missing, category functions will not be compiled. class myDataFunction {}; }; }; };
Attributes
file
The file attribute can override the category's loading path segment.
requiredAddons
The category can skip loading if a required addon is missing by setting its dependency with the requiredAddons attribute.
Function
class CfgFunctions { class TAG { class Category1 { class myFunction {}; }; class Category2 { file = "Path\To\Category"; class myFunction { file = "My\Function\Filepath.sqf"; // file path will be <ROOT>\My\Function\Filepath.sqf", ignoring "Path\To\Category" }; class myFSMFunction { preInit = 1; postInit = 1; ext = ".fsm"; preStart = 1; recompile = 1; }; }; }; };
Attributes
Attribute | Description | Available in | |
---|---|---|---|
Description.ext | config.cpp | ||
file | the file attribute can be used to manually set the file path. | ||
preInit | the preInit attribute (formerly known as "forced") can be set to 1 to call the function upon mission start, before objects are initialized. Passed arguments are ["preInit"] . The function is run in an unscheduled environment.
|
||
postInit | the postInit attribute can be set to 1 to call the function upon mission start, after objects are initialized. Passed arguments are ["postInit", didJIP] . The function is run in a scheduled environment so suspension is allowed, but any long term suspension will halt the mission loading until suspension is done.
|
||
ext | the ext attribute can be used to set function file's type; it can be
|
||
preStart | the preStart attribute can be set to 1 to call the function upon game start, before title screen, but after all addons are loaded. | ||
recompile | the recompile attribute can be set to 1 to recompile the function upon mission start (functions in Description.ext are always compiled upon mission (re)start) |