loadConfig: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Add more See Also)
(Remove the "Leo" tag...)
Line 20: Line 20:


|x2= <sqf>//Using a cache to store loaded configs, since loading configs is very slow and should be done once.
|x2= <sqf>//Using a cache to store loaded configs, since loading configs is very slow and should be done once.
Leo_fnc_getConfig = {
_fnc_getConfig = {
params ["_path"];
params ["_path"];
//initialize cache if not initialized yet
//initialize cache if not initialized yet
Line 35: Line 35:
};
};
//the first call will be slow (~0.1200 ms), but subsequent calls are fast (~0.0050 ms)
//the first call will be slow (~0.1200 ms), but subsequent calls are fast (~0.0050 ms)
["a3\data_f\default_super.rvmat"] call Leo_fnc_getConfig;</sqf>
["a3\data_f\default_super.rvmat"] call _fnc_getConfig;</sqf>


|seealso= [[config greater greater name|>>]] [[configFile]] [[configClasses]] [[isText]] [[isNumber]] [[isArray]] [[isClass]] [[configName]] [[getText]] [[getNumber]] [[getArray]]
|seealso= [[config greater greater name|>>]] [[configFile]] [[configClasses]] [[isText]] [[isNumber]] [[isArray]] [[isClass]] [[configName]] [[getText]] [[getNumber]] [[getArray]]
}}
}}

Revision as of 06:11, 17 March 2022

Hover & click on the images for description
Only available in Development branch(es) until its release with Arma 3 patch v2.10.

Description

Description:
Loads the given file as a Config. It can load .rvmat, .bisurf, .cpp, .bin, .sqm, and description.ext files (both binarized and unbinarized configs are supported).
Loading a config can be very slow. The config should only be loaded once and cached. For example, the result can be stored in a HashMap of File Path - Config pairs. (See Example 2)
Groups:
Config

Syntax

Syntax:
loadConfig path
Parameters:
path: String - Path to the file, which should be in a valid config format.
Return Value:
Config - Loaded config. Returns configNull if the file doesn't exist.

Examples

Example 1:
private _cfg = loadConfig "a3\data_f\default_super.rvmat"; //note: very slow! ~0.1200 ms on tested system getText (_cfg >> "Stage2" >> "uvSource");
Example 2:
//Using a cache to store loaded configs, since loading configs is very slow and should be done once. _fnc_getConfig = { params ["_path"]; //initialize cache if not initialized yet if (isNil "Leo_configCache") then { Leo_configCache = createHashMap; }; private _cfg = Leo_configCache getOrDefault [_path, configNull]; //if path doesn't exist in the cache or cfg is null, load the config if (isNull _cfg) then { _cfg = loadConfig _path; Leo_configCache set [_path, _cfg]; }; _cfg; }; //the first call will be slow (~0.1200 ms), but subsequent calls are fast (~0.0050 ms) ["a3\data_f\default_super.rvmat"] call _fnc_getConfig;

Additional Information

See also:
>> configFile configClasses isText isNumber isArray isClass configName getText getNumber getArray

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note