Jump to content
Sign in to follow this  
eymerich

While { ( ( { alive _x } count Arr ) < 2 ) } Do ...

Recommended Posts

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

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 by dr_strangepete

Share this post


Link to post
Share on other sites

Hey can you wrap that code in "php" tags please? Unreadable for now, really.

Share this post


Link to post
Share on other sites
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
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

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
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

Just ignore my reply. I was way too confused at the end of it.

Share this post


Link to post
Share on other sites
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

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
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
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×