Jump to content
FireWalker

Need guidance on deleteVehicle SOLVED

Recommended Posts

Would someone explain why this line deletes all placed AI units once the mission runs?

It deletes all AI regardless of side. (east, west, civ, geur)  And it cleans up dead units.

It can be tested in the debug console.

 

{{deleteVehicle _x} forEach units _x; deleteGroup _x} forEach allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}};

 

It doesn't matter if the marker is placed or not. And therefore the radius doesn't matter.

 

Shouldn't this only delete AI units from side EAST that are within 60' of the marker?  

 

If someone thinks I should title this topic better please let me know.

 

Fire

  • Like 1

Share this post


Link to post
Share on other sites

always wrap such array after forEach : (allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}})

 

{{deleteVehicle _x} forEach units _x; deleteGroup _x} forEach (allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}});

  • Like 3

Share this post


Link to post
Share on other sites

Ok,

 

That makes sense now that I see it. Without it wrapped it reads the second half as two different command sections? Seems like it ends up reading this section : 

{side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}};

more of a null statement then a command to do anything. It didn't throw any errors, that I could find.

 

Looking at it further:

{{deleteVehicle _x} forEach units _x; deleteGroup _x} forEach allGroups

I guess this is the part that gets read as a command, and thats whats telling it to delete all ai?

 

Fire

  • Like 1

Share this post


Link to post
Share on other sites

I'd blame the lack of brackets in the condition.

{
	{
		deleteVehicle _x;
	} forEach units _x;
	deleteGroup _x;
} forEach allGroups select { side _x == EAST && {((leader _x) distance (getMarkerPos "_marker")) < 60}};

 

  • Like 2

Share this post


Link to post
Share on other sites

@pierremgi  

 

This code works correctly for the situation. With the marker within 60 only EAST AI gets deleted, if the marker is outside of the 60 range, then nothing happens to any of the units:

{{deleteVehicle _x} forEach units _x; deleteGroup _x} forEach (allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}}); 

 

 

 

@Tajin

 

This does not correct the issue. It will still delete all AI units in the map even without the marker close enough:

{{deleteVehicle _x;} forEach units _x; deleteGroup _x;} forEach allGroups select { side _x == EAST && {((leader _x) distance (getMarkerPos "_marker")) < 60}};

 

Tested using the debug in a clean environment with a couple AI from each side.

 

Not trying to call anybody out, just wanted to try to make it clear if someone else swings in and reads through this. Thank you all for the help.

 

Fire

 

(for clarity: the situation here is to delete all the AI from side EAST that are within 60 meters of a marker named: _marker when the code is called)

 

And a link to the mission file if anyone wants to test in the editor:

DropBox

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Typical precedence issue.

forEach wants an array, the first element after it is an array so forEach got what it wants and doesn't care about anything behind that array.

The round brackets basically yell at forEach: "NOT SO FAST" and force the encased commands to be evaluated first.

That's why @pierremgis solution works.

 

Cheers

  • Like 3

Share this post


Link to post
Share on other sites
On 9/22/2017 at 10:10 AM, pierremgi said:

always wrap such array after forEach : (allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}})

 

{{deleteVehicle _x} forEach units _x; deleteGroup _x} forEach (allGroups select {side _x == EAST and {leader _x distance getMarkerPos "_marker" < 60}});

What does the extra curly brackets do inside this deleteVehicle _x code? Does Lazy evaluation work outside a if then?

(allGroups select {side _x == EAST and {leader _x distance getMarkerpos "_marker"<60}});

 

Share this post


Link to post
Share on other sites

Yep, but not very significant difference with few groups. The more BLUFOR groups, the greater difference.

  • 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

×