Inventory system: Find an empty slot with Array

Hello guys,

I’m currently working on an inventory system and now I need to find out which slots are empty, so that I can put the items there.

I guess for that it would be good to use arrays, but I’m not too familiar with them.

Could any of you tell me the rough constellation of a loop through an array to find the slot with the boolean “empty” (preferably in Javascript)?

Thanks in advance :wink:

@Annij, here is one way of testing for empty inventory slots in an array:

#pragma strict

var maxInventorySlots = 5;
var array = new Array();

function Start ()
{
    array.length = maxInventorySlots;
    array[0] = 'hello world';

    for(var index = 0; index < maxInventorySlots; index++)
    {
        if (array[index] == null)
        {
            Debug.Log('Index ' + index + ' is empty.');
        }
    }
}