table.remove not working !

So my inventory is finaly working, i can add items, items are displayed, i can even drop an item from it. However when i drop an item from it, it should remove from inventory. Problem, the table.remove method is not working when i try to remove by slot index (it’s the k in “for k, v in pairs(TABLE_NAME) do”)

Here is my code :
InventoryManager:RemoveItem(player, slotID)

function InventoryManager:RemoveItem(player, slotID)
	if (player.inventory == nil) then return false end
	for k, v in pairs(player.inventory) do
		if (k == slotID) then
			print(k) --Working, console says the correct value
			table.remove(player.inventory, (k)) --Not working it simply does nothing
			return true --Working and after this line too
	return false

I forgot, you should need the AddItem methode, here you go :

function InventoryManager:AddItem(player, itemID) --ItemID is the index of this item (from 0 to 255, ex : 0 = cstm_pistol_glock18), and player you know it
	if (player.inventory == nil) then return false end
	for k, v in pairs(InventoryContent) do
		if (v[0] == itemID) then
			table.insert(player.inventory, table.Count(player.inventory), itemID)
			return true
	return false

I don’t think this is it, but should k be surrounded by parenthesis?

It changes nothing, I can remove them. The fact I added them was that I tried to get the correct index by k-1, I tried various operations, but none seams to be working.

It has no need to be surrounded by parenthesis but it isn’t breaking anything.

What’s the structure of the player.inventory table? It’s just a basic table with numerical key indexes?

The structure is simple it’s a integer index key linked to a complexe matrix that store every data of the linked item, so I can render it or spawn it.

I might be wrong, but I had a problem a bit like this, where stuff wouldn’t remove itself. In the end I solved it by putting something like

timer.Simple( 0, function() table.remove(player.inventory, (k)) )

my code worked a little differently, and I don’t really know what I’m talking about, but it might be worth a try, right?

Sorry, it’s not working it just does nothing… Like before…

[editline]7th July 2014[/editline]

Made it !! It’s enough working items are removed correctly yay !

Here is how i’ve done :

function table.removekey(table, key)
    local element = table[key]
    table[key] = nil
    return element