Hello, after asking for a sorting-function in another thread, I decided to write my own function. The only thing it has to du is to get rid of empty elements in the array, by looking for objects inside the next element and moving them to the empty one.
This works fine for one empty element, but when it comes to two or more empty elements in a row, the function fails, because i’s not looking if the next element is empty too.
How do I write an good and short function for my issue? All in javascript.
function sortInventory(){
for(var iii : int = 0;iii<inventory.Length-1;iii++){
if(inventory[iii] == null){
inventory[iii] = inventory[iii+1];
inventory[iii+1] = null;
}
}
}