table.remove question.

I have a table that is set up something like this.

[lua]table= { [val1]= { val = 1}}[/lua]

I was wondering how I would go about removing [val1] from the table with table.remove

Here is how it looks in my code.
[lua]function PropRemovedInfo(um)
local ID = um:ReadLong()
if !Prop_Info[ID] then return end
table.remove(Prop_Info[ID])

end
usermessage.Hook(“RemoveProp”,PropRemovedInfo)[/lua]

ID is set an int value that is given by the usermessage. The table will already have that int in it as a sub table.
Example
Prop_Info = { [1354] = { val = 0}}
The only problem is that table.remove is not removing the sub table like I need it to. How would I get it to properly remove it.

Prop_Info[ID] = nil

I am still getting used to all the works of tables, but wouldn’t that still leave the sub table there and just nil everything in it?

table.remove is for hash tables IIRC. If you want to remove an index from a table that isn’t a hash table, then you’d have to make the value nil like Co2 showed you

Ok, thanks guys.

Using table.remove on a numerically indexed table will cause all the indexes to be moved down to fill in the gap, so you can use either method depending on what results you want.

[lua]
local function PTable(t,id)
print(“Printing table”,t,id)
for k,v in pairs(t) do
print(k,"=",v)
end
print()
end

local t1a = {1,2,3,4,5,6}
local t1b = {1,2,3,4,5,6}

table.remove(t1a,2) --remove element 2 using remove
t1b[2] = nil --remove element 2 using nil

PTable(t1a,“numeric indexes after remove”)
PTable(t1b,“numeric indexes after nil-set”)

—OUTPUT
–[[
Printing table table: 0x980a090 numeric indexes after remove
1 = 1
2 = 3
3 = 4
4 = 5
5 = 6

Printing table table: 0x9809f40 numeric indexes after nil-set
1 = 1
3 = 3
4 = 4
5 = 5
6 = 6
]]
[/lua]

I know what it does…

Read my post again.

It’s for both hash tables and numeric tables.

I meant to say you should be using table.remove with a hash table if you want the values to move up.