Last active
September 16, 2015 23:52
-
-
Save X39/9a2a6cf971b9d86c0b49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X39_fnc_Scheduler_Create = { | |
/* | |
* Creates the scheduler object if not yet was created | |
* Params: -/- | |
* Return: OBJECT - Scheduler object (also available via missionNamespace variable 'X39_var_Scheduler') | |
* Throws: No | |
* Notes : -/- | |
*/ | |
if(!isNil "X39_var_Scheduler") exitWith {}; | |
private "_scheduleFunction"; | |
X39_var_Scheduler = "EmptyDetector" createVehicleLocal [0, 0, 0]; | |
X39_var_Scheduler setTriggerArea [0, 0, 0, false]; | |
X39_var_Scheduler setVariable["Scheduler_Jobs", []]; | |
_scheduleFunction = str { | |
_jobs = thisTrigger getVariable "Scheduler_Jobs"; | |
_curTime = time; | |
{ | |
if(!isNil "_x") then | |
{ | |
if(_curTime - (_x select 2) >= (_x select 1)) then | |
{ | |
_x set[2, _curTime]; | |
_forEachIndex call (_x select 1); | |
}; | |
}; | |
} foreach _jobs; | |
}; | |
_scheduleFunction = _scheduleFunction select [1, (count _scheduleFunction) - 2]; | |
X39_var_Scheduler setTriggerStatements [_scheduleFunction, "", ""]; | |
}; | |
X39_fnc_Scheduler_AddJob = { | |
/* | |
* Adds a new job to the scheduler | |
* Params: | |
* [ | |
* R - SCALAR - Time between each execution | |
* R - CODE - Code to be executed, code gets following parameter passed: | |
* <SCALAR-UniqueID> | |
* O - BOOLEAN - Shall the first execution be instant | |
* ] | |
* Return: SCALAR - Unique ID of this job (so it can be canceled | |
* Throws: Yes | |
* Notes : -/- | |
*/ | |
if(isNil "X39_var_Scheduler") exitWith { throw "ERR: Scheduler not yet created"; }; | |
params [ | |
["_timeout", -1, [1]], | |
["_code", {}, [{}]], | |
["_execute", false, [false]] | |
]; | |
if(_timeout <= 0) exitWith { throw "ERR: Param1 (timeout) <= 0"; }; | |
if(str _code == "{}") exitWith { throw "ERR: Param2 (executionCode) is empty"; }; | |
((X39_var_Scheduler getVariable "Scheduler_Jobs") pushBack [_timeout, _code, (if(_execute) then {time - _timeout} else {time})]) | |
}; | |
X39_fnc_Scheduler_RemoveJob = { | |
/* | |
* Removes a job from the scheduler | |
* Params: | |
* [ | |
* R - SCALAR - UniqueID of the job you want to remove | |
* ] | |
* Return: -/- | |
* Throws: Yes | |
* Notes : Invalid UniqueIDs which are > 0 wont throw issues and instead just enlarge the joblist! | |
*/ | |
if(isNil "X39_var_Scheduler") exitWith { throw "ERR: Scheduler not yet created"; }; | |
params [ | |
["_uniqueID", -1, [1]] | |
]; | |
if(_uniqueID < 0) exitWith { throw "ERR: UniqueID < 0"; }; | |
(X39_var_Scheduler getVariable "Scheduler_Jobs") set [_uniqueID, nil]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment