Conditional not working in my game

Hello devs,
I am trying to test whether my script is working properly, so I provided the following code:

local enemiestable = mpcontrol.findEnemies(enemies)
if not enemiestable then
	print(enemiestable)
	print(table.find(enemiestable, othermp))	
end

the module function mpcontrol.findEnemies finds the values of various ObjectValue instances and returns them in a nice, neat table. Usually in the script, the table prints as {}.

I also tried if enemiestable ~= nil then and if enemiestable ~= {} then, but both of these are inconsistent.

However, the script I provided is not supposed to print when the table is empty.
How do I fix this?

More importantly, how do I understand how tables work when it comes to their boolean values? The devhub says that tables can store any type of value that isn’t nil.

Thank you in advance.

I’m not sure what the issue is but you could try this:

if enemiestable and #enemiestable > 0 then -- Checks if the table has at least 1 item in it
else
-- Print code here
end

It’s not the most efficient but it’s how I would do it as I’ve had a few issues using if statements in the past.

Hope this helps :slight_smile:

1 Like

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