Jump to content
cidfr

How to release a file handler when using preprocessFileLineNumbers

Recommended Posts

Hello, I'm new to SQF.

 

I'm writting a script to load an external .sqf file containing values stored in a HashMap, in order to have some mission configuration stored outside of a .pbo file for easier changes/tweaks.

So far, the script works as expected. I've placed it in a dummy mission, exported it to multiplaier to generate a .pbo and copied that pbo onto a local server and created the sqf file. The datas are loaded.

However, when I want to make changes in that sqf file while the server is running, I can't save the file and get a message telling that the file is actually busy, as if the file handler wasn't released

 

Does preprocessFileLineNumbers open a file but doesn't close it once processed?

Could the Arma server executable lock the file since it's now an external part of the pbo?

 

How to overcome this? I still can turn the server off, save the file, and then start it again, but I hoped I could save the file in runtime and simply restart the mission

 

Here the script, if needed

Spoiler

params [
    ["_settings_path", "configs" ],
    ["_settings_file_name", "settings.sqf"]
];

private _returnValue = nil;

try
{
    if (!isFilePatchingEnabled) then
    {
        throw "File patching MUST be enabled.";
    };
    diag_log "File patching is enabled." + endl + "Processing.";
    private _fileName = format [ "\%1\%2", _settings_path, _settings_file_name ];
    if !(fileExists _fileName) then
    {
        throw format [ "File '%1' doesn't exist.", _fileName ];
    };
    diag_log format [ "Loading script : '%1'", _fileName ];
    private _settingsScript = compile preprocessFileLineNumbers _fileName;
    diag_log "Script loaded." + endl + "Getting settings now";
    private _settings = call _settingsScript;
    private _settings_Type = typeName _settings;
    if (_settings_Type != "HASHMAP") then
    {
        throw format [ "Unexpected data type for data type." + endl + "Expected : HASHMAP" + endl + "Got : %1", _settings_Type ];
    };
    diag_log "Settings loaded";
    // debug
    { diag_log str [_x, _y] } forEach _settings;
    // -----
    _returnValue = _settings;
}
catch
{
    diag_log format [ "Something went wrong processing the script." + endl + "Exception : %1" + endl + "Returning nil value", _exception ];
};
_returnValue;

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×