If statement passing wrong

If statement:

  local ChunkInvoked = GetChunkRemote:InvokeServer(Chunk)
			
			if ChunkInvoked ~= nil and ChunkInvoked ~= {} then
				print(ChunkInvoked)

What prints:

image

Each table has its own memory address. One empty table isn’t equal another empty table.

print({} == {})

Okay but how do i make sure the table isn’t empty?

If it’s an array you can use the # statement to check if is empty.

1 Like

It’s a dictionary


As bytesleuth said before me, length operator works on arrays, but not on dictionaries.

if next(dictionary) ~= nil then ... end -- at least one element

ADDITIONALLY.

If you need the exact number of elements, you can also count them in a loop. Perhaps table library will be expanded in the future to include a built-in way for counting dictionary elements.

local n = 0
for i in dictionary do
	n += 1
end
print(n)
1 Like

Seems to be working now thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.