Page tree
Skip to end of metadata
Go to start of metadata

Technical Background Info

The below info does not have to be understood in order to use the function library. It is just written for those wanting to know the specifics of how the function library works.

The function library doesn't store functions in global variables, as was done in VBS1. Storing a constant value in a variable is unnecessary and would be a waste of resources, especially when there are dozens of functions available.

Instead, functions are simply "stored" in a defined constant. The constants are all listed in the header file, which is then included at the top of the script. To be more specific, the header file simply lists a number of #defines (one for each function), which look something like the following:

#define fn_vbs_somefunction compile preprocessfile '\vbs2\somewhere\somefunction.sqf'

The PreProcessor Commands does a find/replace operation on scripts before they are run, which replaces the small, easy to use word "fn_vbs_somefunction", with the longer, working syntax to the right of it. Example:

    //The line looks like this when written in a script:
_ret = [player, 5] call fn_vbs_somefunction;
    //The line looks like this after the script is preprocessed and loaded:
_ret = [player, 5] call compile preprocessfile '\vbs2\somewhere\somefunction.sqf';

Sqs scripts and code written in the editor are not preprocessed, so they can not use the function library. #defines are also case sensitive, unlike global variables.

Check Function Availability

To test whether a function is defined in your current version of VBS, check the function's typeName via the following code (a defined function will return "CODE", an undefined function returns nothing):

#include "\vbs2\headers\function_library.hpp"
player sidechat format["fn_vbs_relPos: %1",typename fn_vbs_relPos];

To check availability programatically, due to the undefined status returned by a non-existing function, we have to go about it in a somewhat roundabout way:

if (isNil (typeName fn_vbs_dummy)) then {
player sidechat format["fn_vbs_dummy: %1",_exists];