Jump to content
sabot10.5mm

queue system for running multiple scripts.

Recommended Posts

This is just a concept i had in my head. What i had in mind is say you want to run a script foreach unit, and only want a limited amount of scrips to run at any given time; would it be a good idea to queue 5 to run and finish before the next 5 can run? This script probably wont work, since i cant debug from my phone

missionNamespace setVariable ["queue", 0];
allunits apply {
while {alive _x} do {
_queue = missionNamespace getVariable "queue";
if (_queue >= 10) exitWith {};
missionNamespace setVariable ["queue", (missionNamespace getVariable "queue")+1];

while {what ever is true} do {what ever is here does not matter. its just a concept};
missionNamespace setVariable ["queue", (missionNamespace getVariable "queue")-1];
};
};

 

Share this post


Link to post
Share on other sites

So much lines to obtain a simple definitely  "I am finished running" !

Your while loop is weird (your condition for a simple boolean also).

Are you sure you need to wait for all codes completion? (spawned or execVMed because the called ones are already queued in the scope).

If you need to wait for scripts terminated, then repeated, you should think about repeatable trigger, you can act and deact as you need.

 

... or, referring to your idea, your loop could be:

 

[] spawn {

  while {true} do {
    _code1 = [] spawn code1;

    _code2 = [] execVM "code 2.sqf";

    call code 3;

    ....

   waitUntil { [_code1,_code2] findIf {! scriptdone _x} == -1  };
   sleep (optional)

  };
};

 

EDITED

 

Small example:
 

Spoiler

 

0 = [] spawn {
   while {true} do {
    _code1 = [] spawn {hint "first"; sleep 3};
     _code2 = [] spawn {sleep 3; hint "second"; sleep 3};
    waitUntil { [_code1,_code2] findIf {! scriptdone _x} == -1  };
   };
};
Here _code1 & _code2 are running in parallel, because I chose to spawn them. The reason why I added a sleep in front of the second one to reschedule the hint. Of course it's an example the equivalent code is simple as:

0 = [] spawn {
   while {true} do {
    hint "first"; sleep 3;
    hint "second"; sleep 3;
   };
};

So be sure you need to do all that complication.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

I was thinking more of a queue for repeating scripts, most notably would be applying a loop script to every unit. ive did some tinkering and made each script (+ 1 to a queue variable)  it does not matter to me how this looks, 

missionNamespace setVariable ["queue", 0];
allunits apply {
while {alive _x} do {
_queue = missionNamespace getVariable "queue";
if (_queue >= 10) exitWith {};
missionNamespace setVariable ["queue", (missionNamespace getVariable "queue")+1];

while {what ever is true} do {what ever is here does not matter. its just a concept};
missionNamespace setVariable ["queue", (missionNamespace getVariable "queue")-1];
};
};

 

Share this post


Link to post
Share on other sites

 

If you want to limit the global number of active scripts, you can add something like:

waitUntil (sleep 1; count diag_activeSQFScripts  < 10);

at the head of scripts.

That will not end or decrease the number of script, so you need to take into account how many time you write that. You can't do that for all scripts if you want to see some of them terminated! I mean the waitUntil condition keeps its own script active while FALSE. So you are waiting for some other scripts termination (so, without this check) of course.

 

But, overall, as far as you would manage the CPU load, IMHO it's a weird approach as all scripts have their own workload for CPU.

You can play with diag_FPS instead (each PC has its own performance. So...)

 

Just a remark:

- when bad scripting with plenty of endless scripts,  count diag_activeSQFScripts can reach 1000, 2000 (check in debug console)

- heavy scenarios with plenty of codes can reach 100, 200, even 300 active scripts

- small missions with nothing special but waypoints (as example) have often 10 , 20 active scripts

It's just a general idea.

  • Like 1

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

×