eymerich 11 Posted January 5, 2014 Hi all as the topic says: i can't get this condition evaluated in my script. --lines of code While { ( ( { alive _x } count Arr ) < 2 ) } Do { // condizione non eseguita hint format ["check di flow 1-1 %1", ( { alive _x } count Arr )]; sleep 5; }; --- Where: Arr = an array storing 16 object (16 man) - --- Full code: -- //creates groups sleep 0.5; hint "go flow1"; Arr = []; _randomPos = [position Sp1, position Sp2, position Sp3, position Sp4] call BIS_fnc_selectRandom; Gr1 = [_randomPos, side G, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call BIS_fnc_spawnGroup; Arr = Arr + ( units Gr1 ); sleep 0.5; Gr2 = [_randomPos, Side G, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call BIS_fnc_spawnGroup; Arr = Arr + (Units Gr2); hint format ["%1 Arr", count Arr]; sleep 1; {removeHeadgear _X; removeUniform _X; removeAllAssignedItems _X} foreach Arr; sleep .5; { _x addUniform "U_C_HunterBody_grn"; _x addHeadgear "H_Booniehat_grn"; _x addEventHandler ["Hit", {_this exec "Hit.sqs"}]} foreach Arr; null = [Gr1, position defend] call BIS_fnc_taskDefend; null = [Gr2, position defend] call BIS_fnc_taskDefend; Sleep 3; While { ( ( { alive _x } count Arr ) < 2 ) } Do { hint format ["check flow 1-1 %1", ( { alive _x } count Arr )]; sleep 5; }; /// flow1 part 2 hint "go - flow part 2"; [...] Thanks in advance Share this post Link to post Share on other sites
dr_strangepete 6 Posted January 5, 2014 (edited) you're trying to use _x outside of a loop's scope -> nothing is defining _x where you're using it. you probably should use a { } foreach Arr ---------- Post added at 18:20 ---------- Previous post was at 18:18 ---------- i take that back, didn't realize thats a valid use....i was mistaken is there a specific error you receive or it doesn't function as expected? Edited January 5, 2014 by dr_strangepete Share this post Link to post Share on other sites
tryteyker 28 Posted January 6, 2014 Hey can you wrap that code in "php" tags please? Unreadable for now, really. Share this post Link to post Share on other sites
eymerich 11 Posted January 6, 2014 you're trying to use _x outside of a loop's scope -> nothing is defining _x where you're using it. you probably should use a { } foreach Arr ---------- Post added at 18:20 ---------- Previous post was at 18:18 ---------- i take that back, didn't realize thats a valid use....i was mistaken is there a specific error you receive or it doesn't function as expected? No error. Basically the condition is not evalutated because the "while cod"e desn't show this hint (hint format ["check flow 1-1 %1", ( { alive _x } count Arr )]; ) inside of it. @Dr_stranepete I am sorry. How do I post with the Php Code? In any case I have removed non essential lines and the script now looks like this Arr = []; Gr1 = [_randomPos, side G, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call BIS_fnc_spawnGroup; Arr = Arr + ( units Gr1 ); sleep 0.5; Gr2 = [_randomPos, Side G, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call BIS_fnc_spawnGroup; Arr = Arr + (Units Gr2); While { ( ( { alive _x } count Arr ) < 2 ) } Do { hint format ["check flow 1-1 %1", ( { alive _x } count Arr )]; sleep 5; }; My guess, now I am not at home, is that while code doesn't accept twice the curled bracer so the function should be written like this: While { ( ( ( alive _x ) count Arr ) < 2 ) } Do Share this post Link to post Share on other sites
mariodu62 5 Posted January 6, 2014 private "_test"; _test = { alive _x } count Arr; While { _test < 2} do { what you want... _test = { alive _x } count Arr; }; Share this post Link to post Share on other sites
tryteyker 28 Posted January 6, 2014 In the above example _test will only be evaluated once, so the condition has to be right from the beginning or else the while loop will be skipped. unless that was just an example of writing in php code in which case im bad. Share this post Link to post Share on other sites
mariodu62 5 Posted January 6, 2014 In the above example _test will only be evaluated once, so the condition has to be right from the beginning or else the while loop will be skipped.unless that was just an example of writing in php code in which case im bad. No, _test is checked before AND in the loop... Share this post Link to post Share on other sites
tryteyker 28 Posted January 6, 2014 Just ignore my reply. I was way too confused at the end of it. Share this post Link to post Share on other sites
eymerich 11 Posted January 6, 2014 private "_test"; _test = { alive _x } count Arr; While { _test < 2} do { what you want... _test = { alive _x } count Arr; }; Thanks all. This could work although i don't understand what's wrong with my code. I'll try and i report the results. :) Share this post Link to post Share on other sites
Larrow 2822 Posted January 6, 2014 While { ( ( { alive _x } count Arr ) > 2 ) } Do You are spawning two eight man groups so straight away the number alive is greater than 2 so it skips the while loop. You need (as shown above) while there is more than 2 alive (greater than) do .... Share this post Link to post Share on other sites
mariodu62 5 Posted January 6, 2014 While { ( ( { alive _x } count Arr ) > 2 ) } Do You are spawning two eight man groups so straight away the number alive is greater than 2 so it skips the while loop. You need (as shown above) while there is more than 2 alive (greater than) do .... you are right... Share this post Link to post Share on other sites
eymerich 11 Posted January 6, 2014 While { ( ( { alive _x } count Arr ) > 2 ) } Do You are spawning two eight man groups so straight away the number alive is greater than 2 so it skips the while loop. You need (as shown above) while there is more than 2 alive (greater than) do .... :butbut: Got a new lesson: never script when i'm tired. I'll try your suggestion anyway thanks Share this post Link to post Share on other sites