Functions in seperate sqf file

Kill your comrades. Wholesale
Post Reply
tryteyker
Posts: 104
Joined: Wed Feb 20, 2013 9:17 pm
Location: Sweden / Germany (depends really)

Functions in seperate sqf file

Post by tryteyker »

Hi,
I'm kinda running against a wall with this problem. What I need to (focus on need to, I can't really do it any other way) do is execute a couple of functions from an external sqf file.

To help illustrate, this is what I'm doing right now:

init.sqf:

Code: Select all

[] call compile preprocessFileLineNumbers "functions.sqf";
functions.sqf:

Code: Select all

trt_fnc_cleanup = {
private ["_group1","_group2"];
_group1 = _this select 0;
_group2 = _this select 1;
sleep 0.5;
{deletevehicle _x} foreach units _group1 + units _group2;
};

trt_fnc_cleanup_1 = {
private ["_group1","_script","_obj1"];
_script = _this select 0;
_group1 = _this select 1;
_obj1 = _this select 2;
sleep 5;
terminate _script;
sleep 0.5;
{deletevehicle _x} foreach units _group1;
sleep 0.5;
nul = [_obj1] execVM "tasks\dynamictasks.sqf";
};

trt_fnc_cleanup_2 = {
private ["_group1","_script","_obj1","_group2"];
_script = _this select 0;
_group1 = _this select 1;
_group2 = _this select 2;
_obj1 = _this select 3;
sleep 1;
terminate _script;
sleep 0.5;
{deletevehicle _x} foreach units _group1 + units _group2;
sleep 0.5;
hint format ["Obj: %1",taskstate _obj1];
nul = [_obj1] execVM "tasks\dynamictasks.sqf";
};


trt_fnc_cleanup_3 = {
private ["_group1","_script","_obj1","_obj2"];
_script = _this select 0;
_group1 = _this select 1;
_obj1 = _this select 2;
_obj2 = _this select 3;
sleep 5;
terminate _script;
sleep 0.5;
{deletevehicle _x} foreach units _group1;
sleep 0.5;
nul = [_obj1,_obj2] execVM "tasks\dynamictasks.sqf";
};

trt_fnc_cleanup_4 = {
private ["_group1","_group2","_script","_obj1","_obj2"];
_script = _this select 0;
_group1 = _this select 1;
_group2 = _this select 2;
_obj1 = _this select 3;
_obj2 = _this select 4;
sleep 5;
terminate _script;
sleep 0.5;
{deletevehicle _x} foreach units _group1 + units _group2;
sleep 0.5;
nul = [_obj1,_obj2] execVM "tasks\dynamictasks.sqf";
};

trt_fnc_cleanup_5 = {
private ["_group1","_group2","_script","_obj1","_obj2","_obj3"];
_script = _this select 0;
_group1 = _this select 1;
_group2 = _this select 2;
_obj1 = _this select 3;
_obj2 = _this select 4;
_obj3 = _this select 5;
sleep 5;
terminate _script;
sleep 0.5;
{deletevehicle _x} foreach units _group1 + units _group2;
sleep 0.5;
nul = [_obj1,_obj2,_obj3] execVM "tasks\dynamictasks.sqf";
};
Now the functions are used in 15 different sqf scripts (hence why I cannot put them in every single script). An example below:

Code: Select all

while {flying} do {
if (vehicle player != uh1h) exitWith {
	_pktsk2 setTaskState "failed";
	[trtask3,opforgroup,_bluforsquad,_pktsk2] call trt_fnc_cleanup_2;
};
(Ignore the mission };, there's more stuff inside the loop)

The thing is, the function doesn't get executed. I've tested using Radio Bravo for debug and the function works, but I'm not sure what to do against it. Will preprocessing in every script work? This seems unlikely as I already did that in the init.sqf though. Dynamictasks.sqf is just a script which selects a random mission and deletes all previous objectives assigned. Ideas? :(

//Ninja-edit
Preprocessing in the respective sqf file didn't work either.

//Edit2

Using spawn might help. Should've remembered the basic rule:
spawn = function / code with sleep
call = function / code without sleep.

Fixed the issue.

Post Reply