Larrow/CfgFunctionsAdvanced – User
Lou Montana (talk | contribs) m (Text replacement - "\{\{ *codecomment *\| *\/\/ *([^ ]+) *\}\} " to "{{cc|$1}}") |
Lou Montana (talk | contribs) m (Text replacement - "\{\{( *)Important( *)\|" to "{{$1Feature$2|$2important$2|") |
||
(One intermediate revision by the same user not shown) | |||
Line 9: | Line 9: | ||
class <span style="color:teal;">myFunction</span> | class <span style="color:teal;">myFunction</span> | ||
{ | { | ||
preInit = 1; {{cc|(formerly known as "forced") 1 to call the function upon mission start, <u>before</u> objects are initialized. Passed arguments are ["preInit"]}} | preInit = 1; {{cc|(formerly known as "forced") 1 to call the function upon mission start, <u>before</u> objects are initialized. Passed arguments are ["preInit"]}} | ||
postInit = 1; {{cc|1 to call the function upon mission start, <u>after</u> objects are initialized. Passed arguments are ["postInit", didJIP]}} | |||
preStart = 1; {{cc|1 to call the function upon game start, before title screen, but after all addons are loaded (config.cpp only)}} | |||
ext = ".fsm"; {{cc|Set file type, can be ".sqf" or ".fsm" (meaning scripted FSM). Default is ".sqf".}} | |||
headerType = -1; {{cc|Set function header type: -1 - no header; 0 - default header; 1 - system header.}} | |||
recompile = 1; {{cc|1 to recompile the function upon mission start (config.cpp only; functions in description.ext are compiled upon mission start already)}} | |||
}; | |||
}; | }; | ||
}; | }; | ||
}; | }; | ||
All of these attributes are case sensitive. | All of these attributes are case sensitive. | ||
==== Pre and Post Init ==== | ==== Pre and Post Init ==== | ||
Line 83: | Line 89: | ||
* '''_fnc_scriptNameParent''': [[String]] - Name of q function from which the current one was called (_fnc_scriptName used when not defined) | * '''_fnc_scriptNameParent''': [[String]] - Name of q function from which the current one was called (_fnc_scriptName used when not defined) | ||
<!--* '''_fnc_scriptMap''': ARRAY - List of all parent scripts (available only in debug mode 1 and higher, see [[#Debug_Mode|above]]).--> | <!--* '''_fnc_scriptMap''': ARRAY - List of all parent scripts (available only in debug mode 1 and higher, see [[#Debug_Mode|above]]).--> | ||
{{ | {{Feature|important|Do not modify these values!}} | ||
Line 94: | Line 100: | ||
# '''Save and log script map''' | # '''Save and log script map''' | ||
#* Variable ''_fnc_scriptMap'' tracking script execution progress is stored in functions header and it's printed to debug log. | #* Variable ''_fnc_scriptMap'' tracking script execution progress is stored in functions header and it's printed to debug log. | ||
{{ | {{Feature|important|Function recompiling has to be allowed!}} |
Latest revision as of 02:11, 7 February 2021
Attributes
Apart from already mentioned file, function class can have additional attributes:
class CfgFunctions { class myTag { class myCategory { class myFunction { preInit = 1; // (formerly known as "forced") 1 to call the function upon mission start, before objects are initialized. Passed arguments are ["preInit"] postInit = 1; // 1 to call the function upon mission start, after objects are initialized. Passed arguments are ["postInit", didJIP] preStart = 1; // 1 to call the function upon game start, before title screen, but after all addons are loaded (config.cpp only) ext = ".fsm"; // Set file type, can be ".sqf" or ".fsm" (meaning scripted FSM). Default is ".sqf". headerType = -1; // Set function header type: -1 - no header; 0 - default header; 1 - system header. recompile = 1; // 1 to recompile the function upon mission start (config.cpp only; functions in description.ext are compiled upon mission start already) }; }; }; };
All of these attributes are case sensitive.
Pre and Post Init
preInit and postInit attributes are truly powerful ones, as they let you execute your function at the beginning of every mission. Use them with caution!.
preInit are called unscheduled so suspension is not allowed. Parameters passed are [ "preInit" ].
postInit are called scheduled so suspension is allowed but any long term suspension will halt the mission loading until suspension has finished. Parameters passed are [ "postInit", didJIP ].
- Any scripting error will prevent the mission from being loaded correctly
- Server admins might blacklist your addon if they find out you're using the function for hacking.
Header Types
The different header types add code to the begining of your functions that can..
- Set up the Meta Variables _fnc_scriptParent and _fnc_scriptName
- Name the current scope via the command scriptName
- Adds debug information by saving the current execution order in the Array _fnc_scriptMap.
- No Header
- Adds nothing, literally adds a blank String to the begining of your function. The function will have no debug or Meta Variables assigned for it and the scope will not be named.
- System Header
- Incorporates the Meta Variables _fnc_scriptParent. Also names the current scope.
private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName}; scriptName '%1';
- Default Header
- The default header changes based on the current Debug Mode
- Debug Mode 0 - default
- Incorporates the Meta Variables _fnc_scriptParent and _fnc_scriptName and names the current scope.
- Debug Mode 0 - default
private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName}; private _fnc_scriptName = '%1'; scriptName _fnc_scriptName;
- Debug Mode 1
- As per Debug Mode 0 and also saves the current execution order in the Array _fnc_scriptMap.
- Debug Mode 1
private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName}; private _fnc_scriptName = '%1'; scriptName _fnc_scriptName; private _fnc_scriptMap = if (isNil '_fnc_scriptMap') then {[_fnc_scriptName]} else {_fnc_scriptMap + [_fnc_scriptName]};
- Debug Mode 2
- As per Debug Mode 1 and also outputs execution order using textLogFormat ( textLogFormat is not available in the retail version of Arma3 ) is it available in Diagnostics exe?
- Debug Mode 2
private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName}; private _fnc_scriptName = '%1'; scriptName _fnc_scriptName; private _fnc_scriptMap = if (isNil '_fnc_scriptMap') then {[_fnc_scriptName]} else {_fnc_scriptMap + [_fnc_scriptName]}; textLogFormat ['%1 : %2', _fnc_scriptMap joinString ' >> ', _this];
Meta Variables
System is adding header with basic meta data to all functions. Following local variables are declared there:
- _fnc_scriptName: String - Function name (e.g., myTag_fnc_myFunction)
- _fnc_scriptNameParent: String - Name of q function from which the current one was called (_fnc_scriptName used when not defined)
Debug Mode
Developers can access several debug modes using BIS_fnc_functionsDebug function.
- No debug
- Default
- Save script map
- Variable _fnc_scriptMap tracking script execution progress is stored in function header
- Save and log script map
- Variable _fnc_scriptMap tracking script execution progress is stored in functions header and it's printed to debug log.