To fix what you requested you need to change the logic for the add item function. You shouldn't base it on slot object matching a slot ID that increases when you add an item. You should instead run a loop for each x to check for an empty slot which is "" in the array and then add the item at the array position 'loopindex', or if it doesn't find "" then the inventory is full.
edit: looks like you might be doing that already if you remove the slot object condition. The other problem is that using 'give' is not removing items from the array. It looks for an invslot_1.slotID that is not referenced by conditions