Sending empty table, but it shows up as occupied?

When I send an empty table({}) through net.WriteTable, it appears to be not be empty.

Here is my code:

SERVER:



net.Start("test_update")
	net.WriteUInt(1, 16);
	net.WriteTable({});
net.Send(self);


CLIENT:



net.Receive("test_update", function()
	local num = net.ReadUInt(16);
	local tbl = net.ReadTable();
	
	if (tbl == {}) then
		print("TBL IS EMPTY")
	end

        LocalPlayer().MyTable[num] = tbl;
end)


And the MyTable is just setup like LocalPlayer().MyTable = {};

Any ideas why it isn’t recognizing that the table doesn’t have any entries?

Thanks.

EDIT:

Ok, I ran a test like so:



concommand.Add("test_emptytbl", function()
	local tbl = {};
	tbl[1] = {};
	if (tbl[1] == {}) then
		print("ok?")
	else
		print("no")
	end
end)


It printed out “no”.

is there anyway to see if a table is created, but it isn’t occupied by any variables?

Thanks.

Tables aren’t compared by what they hold, they’re compared by reference. tbl == {} will never be true. If your table is going to be like an array (using sequential keys starting from 1), then you can check if it’s empty like this.
[lua]if (#tbl == 0) then
print(“TBL IS EMPTY”)
end[/lua]
Alternatively, for a more general approach
[lua]if (!next(tbl)) then
print(“TBL IS EMPTY”)
end[/lua]
If you don’t understand anything I just said, just use the second option.

No, i completely understand. Thank you very much.