davidoss 550 Posted August 31, 2016 Hi guys. Once again my own code has overrun my IQ capabilities. Need here a help. I am having fun on some new mission project using Zenophon's Framework and CBA functions. To fit assumptions first stage of this scenario i had to write some complex code which is almost so much each other dependent that i can barely read&fallow it for my self. I am now at end of making stage 1 of this and i am stack. I need to spawn code from itself with different param each time. The param are index from markers array: _outpostst = ["outpost1_1","outpost1_2","outpost1_3","outpost1_4"]; First time the code is executed from outside with param which is one of index of that array. null = (selectRandom _outposts) spawn fnc_task_def_outpost; Now when the first run is done i need to spawn it again with different param value each time, so many times - how many unique indexes left and all from end of that code. For any ideas how to achieve that I will be grateful. Share this post Link to post Share on other sites
theend3r 83 Posted August 31, 2016 I think you don't want to call a code from itself (making it recursive). You just want to run it for a few params, right? If so, then save it as a function (e.g. fnc_initTask) and {_x spawn fnc_initTask} forEach ["outpost1_1","outpost1_2","outpost1_3","outpost1_4"]; Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Unfortunately this is not the case. It cant run for all indexes at once or be spawned again until the first one are not complete. Share this post Link to post Share on other sites
theend3r 83 Posted August 31, 2016 Add a waitUntil {sleep 5; *some condition checking if the previous script has finished*}; to the start? Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Lets make it simply: there are an array with 4 markers one index from that array already in game we need to remove it pickup one from 3 left run the code again with selected param exit first run what is here wrong? Share this post Link to post Share on other sites
theend3r 83 Posted August 31, 2016 OK, if you really want that recursion then just do it. //fnc_taskInit params ["_oaArray"]; //an array equal to ["outpost1_1","outpost1_2","outpost1_3","outpost1_4"] _oa = _oaArray select 0; /*Your script*/ _oaArray = _oaArray - [_oa]; if (count _oaArray > 0) then {[_oaArray] spawn fnc_taskInit}; 1 Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Thanks but is not that i am really want recursion i just do not knew how to do this right in such circumstances. Whats wrong is with recursion when the param is each time different? I could just spawn bunch of enemies and defenders on each outpost make for each a task but this will be something about 200 units at once i cant do that Its need to be done in more controlled way Share this post Link to post Share on other sites
theend3r 83 Posted August 31, 2016 Nothing wrong with it but it's usually preferable to do it some other way to not over-complicate the code and have more control over its execution. In this case, for example, you could assign a handler to the code and use scriptDone to check if the next run should start or make a global variable that would serve as an index or something. This is probably just nitpicking, though. 1 Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Oh you are genius, this is what i wanted. Man how i could forgot that. Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Can this be compacted somehow? //unscheduled [] spawn { //scheduled private _outposts = ["outpost1_1","outpost1_2","outpost1_3","outpost1_4"]; { _x spawn fnc_spawn_guard; } forEach _outposts; private _oa = selectRandom _outposts; private _handledefend = _oa spawn fnc_task_def_outpost; waitUntil {sleep 60; scriptDone _handledefend}; _outposts = _outposts - [_oa]; _oa = selectRandom _outposts; _handledefend = _oa spawn fnc_task_def_outpost; waitUntil {sleep 60; scriptDone _handledefend}; _outposts = _outposts - [_oa]; _oa = selectRandom _outposts; _handledefend = _oa spawn fnc_task_def_outpost; waitUntil {sleep 60; scriptDone _handledefend}; _outposts = _outposts - [_oa]; _oa = _outposts select 0; _handledefend = _oa spawn fnc_task_def_outpost; waitUntil {sleep 60; scriptDone _handledefend}; defenced = true; }; Share this post Link to post Share on other sites
theend3r 83 Posted August 31, 2016 //unscheduled [] spawn { //scheduled private _outposts = ["outpost1_1","outpost1_2","outpost1_3","outpost1_4"]; { _x spawn fnc_spawn_guard; } forEach _outposts; _n = count _outposts; for "_i" from 1 to _n do { _oa = selectRandom _outposts; _outposts = _outposts - [_oa]; _handledefend = _oa spawn fnc_task_def_outpost; waitUntil {sleep 5; scriptDone _handledefend}; }; defenced = true; } Do not use sleep 60; as if you finish the objective when the countdown starts, you'll have to wait a minute for anything to happen. The condition check isn't demanding either, it would be fine even without sleep. 1 Share this post Link to post Share on other sites
davidoss 550 Posted August 31, 2016 Thank you. Little delay between task are not that bad. Share this post Link to post Share on other sites