![]() |
|
#1
|
|||
|
|||
![]() Quote:
![]() Quote:
![]() As a note to your example: Code:
private void DestroyAircrafts(IGamePlay game) { foreach (int army in game.gpArmies()) foreach (var group in game.gpAirGroups(army)) foreach (var item in group.GetItems()) ((AiAircraft)item).Destroy(); } Code:
if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0) About the initial problem: Looks like I have to look a bit closer to see what causes this. |
#2
|
|||
|
|||
![]()
Oh wait I had an idea:
If I destroyed the Aircraft this should change the content of the getItems() array. This will confuse the foreach loop and it will skip some aircraft. Obviously the aircrafts are destroyed with a small delay, that's why it is working for some aircraft and some not. Solution: Store the aircraft to destroy in a seperate list first. Then loop over this list and destroy the aircrafts in it. This way even if the content of getItems() is changed, the content of the list stays the same ![]() I'll check this and report back. |
#3
|
|||
|
|||
![]() Quote:
![]() |
#4
|
|||
|
|||
![]()
I am absolutely sure that group.GetItems() does not return a direct reference to an internal list of aircraft, but makes a copy. So the trick with the list is not needed.
|
#5
|
|||
|
|||
![]()
Yes it returns a copy. However as I used a "for" loop I got the updated copy of the list for every iteration of the loop. Hence the list has changed for every iteration and the indices didn't match anymore to the updated list.
I changed the code to use a "foreach" loop. It's now the same code as yours, only added checks against null references. Last edited by 41Sqn_Banks; 12-18-2011 at 11:45 AM. |
#6
|
|||
|
|||
![]()
Ok
Whilst its nice of you to be putting these scripts up for general use........... Perhaps for the sake of those that don't understand why you would want to have to use such a script, you can in future put an explanation of the scripts use and reason of its need. I understand clearing old aircraft frees up the missions resources and clears old planes from airfields etc etc. Not everyone will know that though. Thxz |
![]() |
|
|