"Using '#' on a table without an array part is likely a bug" But it's not a bug? How do I get these errors out of my script

I’m getting this “error” (the script runs fine, and it doesn’t cause any bugs): “using ‘#’ on a table without an array part is likely a bug”

Here’s an example of where I’m getting it:

for i = 1, (currentEnemySupport and currentEnemySupport[1] and #currentEnemySupport) or 1, 1 do
		if currentEnemySupport[i] ~= nil then
               ...
		end
	end

The #currentEnemySupport gets underlined red and lights up everywhere in my script as an error which is very annoying to look at. Basically my currentEnemySupport variable is either a singular table/dictionary which is a card variable, or it’s an array of multiple support cards.

The checks before using the # on the table make sure that it’s an array rather than a singular card/dictionary so this won’t ever cause any issues, so I need to know how to get rid of these error lines as I use this same check in many places.

Here’s where I assign the variables for currentEnemySupport:

function BattleClient.SetupCurrentSupports() -- setup supports
	if currentPlayerCard == nil or currentEnemyCard == nil then return end
	local slotNumber = currentPlayerCard.SlotNumber
	local eSlotNumber = currentEnemyCard.SlotNumber
	
	if enemySupportCards[eSlotNumber] then
		if not enemySupportCards[eSlotNumber][1] then
			currentEnemySupport = {enemySupportCards[eSlotNumber]}
		else
			currentEnemySupport = enemySupportCards[eSlotNumber]
		end
	else
		currentEnemySupport = {}
	end
	if playerSupportCards[slotNumber] then
		if not playerSupportCards[slotNumber][1] then
			currentPlayerSupport = {playerSupportCards[slotNumber]}
		else
			currentPlayerSupport = playerSupportCards[slotNumber]
		end
	else
		currentPlayerSupport = {}
	end
end

(I use the same checks for currentPlayerSupport and don’t get the error lines so I have no idea what’s wrong.

I’ve messed with a few of the studio settings but can’t find any that disable the error lines. But I also don’t want to disable all errors lines because usually they’re correct and there’s an error

1 Like

Put --!nocheck in the script. Make sure to put it in the VERY first code of the script.

1 Like

that didn’t quite work but after a quick google search of that i found --!nolint which did work

You can also try manually adding a type to the variable, however using --!nolint directly will disable all behavior warnings. You should prefer to disable this specific warning with --!nolint TableOperations, other lints can still be useful in catching bugs and mistakes.

1 Like

can you explain what is that if you have some free time :sweat_smile:

Putting --!nolint inside a Script disables all Linting warnings. You can read more about what the Linter is here:

3 Likes