I have a buffer named Stockpile that holds many entities. I am trying to sort through the stockpile to see if the entities have expired. I have used the following code:
i := Stockpile.NumMU; if i>0 then Repeat if EventController.SimTime - Stockpile.MU(i).TimeCreated > 31449600 then Stockpile.MU(i).move(BufferExpired); end; i := i - 1; until Stockpile.NumMU=0 OR i=0; end;
But I am worried Buffer.NumMU doesnt correctly refer to the entities. If there are currently 5 entities within the buffer but these entities are entity number 10, 11, 12, 13, 14 - wont Buffer.NumMU return 5? Thus none of the entities will be reffered to?
Any help around this would be appreciated!
To access the MUs in an Buffer, you can try using "contentslist" attribute.Try the following code
for var i :=1 to buffer.contentslist.ydim
part := buffer.contentslist[1,i]
if part.<attribute> = expires then
Also you'll need to update/carry the information on the MUs, so as to identify it as expired.
Hope this helps.
Thank you Varun. Another solution I thought of is:
i := Stockpile.statNumIn; j := Stockpile.NumMU; if j>0 then Repeat if EventController.SimTime - Stockpile.MU(i).TimeCreated > 31449600 then Stockpile.MU(i).move(BufferExpired); end; j := j - 1; i := i - 1; until j=0; end;
This will find the maximum .MU(i), thus the last entity created. Do you agree?
as Varun_B already said, you need to access the contentlist of the buffer. For your method it means the following:
i := Stockpile.NumMU; if i>0 then for local x:= i downto 1 if EventController.SimTime - Stockpile.contentlist[1,i].TimeCreated > 31449600 then Stockpile.contentlist[1,i].move(BufferExpired); end; i := i - 1;
Stockpile.MU(i) is not refering the the position of the MU in the pile.