Space Engineers

Space Engineers

Assembly Cleaning
Psicraft 12 Jan, 2015 @ 11:18pm
When moving items from Assembler's Inventory, for loop should count backwards.
Change this:
for (int i = 0; i < assemblerItems.Count; i++) { assemblerInv.TransferItemTo(containerDestination, i, null, true, null); }
To this:
for (int i = assemblerItems.Count - 1; i >= 0; i--) { assemblerInv.TransferItemTo(containerDestination, i, null, true, null); }

Reason
When you finish moving a stack — with other items still in the inventory — the index i will increase but the Count will decrease. You will have skipped the item that moved to the first spot.

If you do the loop backwards this problem won't occur.
< >
Showing 1-2 of 2 comments
Reptar  [developer] 13 Jan, 2015 @ 12:05am 
You're absolutely right. I had tested this, late at night when I wasn't thinking, and saw the the item count didn't go down when an item was moved, and the next item in the loop seemed to be correct. Thinking back, I wasn't getting a new list of items after one was moved, so of course the next item in the index was correct. Really nice catch, thanks a ton for pointing it out.
Psicraft 13 Jan, 2015 @ 12:23am 
You're welcome! I ran into this problem in my own scripts.
< >
Showing 1-2 of 2 comments
Per page: 1530 50