Jump to content

Recommended Posts

ive been trying to run this code the problem is that once one of the conditions in the "waitUntil" is true it keeps looping non stop, i tried to delete the group that was killed as you see below, but it didnt help. if anyone has any ideas it would be great.

 

while {true} do {
waitUntil {({alive _x} count units A == 0) or ({alive _x} count units B == 0)};
hint "boom yah";
A forgetTarget player1; // A & B are group names
B forgetTarget player1;
sleep 3;
};

if (({alive _x} count units A) == 0) then {deleteGroup A};
if (({alive _x} count units A) == 0) then {deleteGroup B};

Share this post


Link to post
Share on other sites
while {true} do {

Is gonna make it run forever, at least until the mission is over. Just remove the while loop:

waitUntil {({alive _x} count units A == 0) or ({alive _x} count units B == 0)};
hint "boom yah";
A forgetTarget player1; // A & B are group names
B forgetTarget player1;
sleep 3;
if (({alive _x} count units A) == 0) then {deleteGroup A};
if (({alive _x} count units A) == 0) then {deleteGroup B};

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/5/2021 at 4:37 AM, beno_83au said:

while {true} do {

Is gonna make it run forever, at least until the mission is over. Just remove the while loop:


waitUntil {({alive _x} count units A == 0) or ({alive _x} count units B == 0)};
hint "boom yah";
A forgetTarget player1; // A & B are group names
B forgetTarget player1;
sleep 3;
if (({alive _x} count units A) == 0) then {deleteGroup A};
if (({alive _x} count units A) == 0) then {deleteGroup B};

 

thx, but i want this code to activate whenever a group is killed not just once, but the problem is once a group is all dead it keeps repeating without removing that group from the list

Share this post


Link to post
Share on other sites

Try spawning them in separately, you should also name your groups better (not just A and B) to avoid potential conflicts and confusion:

 

{

 nul = [_x] spawn {

  params ["_group];

  waitUnitl {({alive _x} count (units _group)) == 0};

  // your code, including delete group

 };

} forEach [groupA,groupB];

 

The thing about that while loop is that your script will continue to run the loop forever. So your script won't run any code after the loop.

Share this post


Link to post
Share on other sites

Hehehe, I was just typing when beno_83au posted. So, yes, in the way you have coded the while loop will run forever (or at least until the mission is over) and the deleteGroups will never be reached.

 

One alternative to that would be to place these two commands inside the while loop. You will most probably want to add some check to see whether they have been deleted before trying to delete them. This could possibly look like (replicating your code and adapting)

while {true} do {
	waitUntil {({alive _x} count units A == 0) or ({alive _x} count units B == 0)};
	hint "boom yah";
	A forgetTarget player1; // A & B are group names
	B forgetTarget player1;
	sleep 3;

	// Check if group A is empty
	if (!(isNull A)) then {
		if (({alive _x} count units A) == 0) then {deleteGroup A};
	};
	
	// Check if group A is empty
	if (!(isNull B)) then {
		if (({alive _x} count units B) == 0) then {deleteGroup B};
	};
};

This is a quite naive implementation though (and I think that you have mistyped the condition for the second deleteGroup command). In this way, the condition to checked in order to delete or not a group is doubly checked. Once in the waitUntil and once at the last two checks before deleting the groups. Additionally, the hint you have inside the while loop will run every 3 seconds, which I believe is not what you really want to achieve.

 

I am not sure exactly what you are trying to achieve so I am not sure I can provide a good solution to your problem. What you have coded will run forever even if the two groups are emptied. I don't think that this is a good way to go about it. beno_83au has provided a valid and rather nice solution to your problem.

  • 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

×