Larrow – User

From Bohemia Interactive Community
Revision as of 20:35, 15 January 2017 by Larrow (talk | contribs) (Created page with "=== Attributes === Apart from already mentioned ''file'', function class can have additional attributes: class CfgFunctions { class <span style="color:green;">myTag</span>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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
Debug Mode 0 - default
Incorporates the Meta Variables _fnc_scriptParent and _fnc_scriptName and names the current scope.
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.
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?
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)
Do not modify these values!


Debug Mode

Developers can access several debug modes using BIS_fnc_functionsDebug function.

  1. No debug
    • Default
  2. Save script map
    • Variable _fnc_scriptMap tracking script execution progress is stored in function header
  3. Save and log script map
    • Variable _fnc_scriptMap tracking script execution progress is stored in functions header and it's printed to debug log.
Function recompiling has to be allowed!