Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Function for calling assert() multiple times doesn't work, why? [lol it was working perfectly fine]

local function assertMulti(...)
	local args = {...}
	local helperTable = {}
	for i=1, #args do
		if i % 2 == 1 then -- if le position is an odd number
			table.insert(helperTable, #helperTable + 1, assert(args[i], args[i+1])) -- add a new entry to the helperTable which is an assert() with the respective values of the entry that i is at and the entry after that
		end
	end
	return helperTable -- return that table
end
assertMulti(false, "oh", false, "also oh") -- oh boi

This vararg function is meant to call assert() multiple times at once easily.

However, it outputs this.

Why does this happen, and how can I fix it?

(My intentions: I am editing my Variable & Functions Module (shared on le roblox site), and I want to be able to assert for errors more easily when people use the functions.)

#edit point oh

i'm mentally retarded

it works perfectly fine

1 answer

✓ Accepted answer

Im not sure what exactly you want to do.

You make it call assert(args[i], args[i + 1]) if the index is an odd number.

The first entry in your vararg is false and 2nd one is "oh", and since 1 is an odd number, your function calls assert(false, "oh"), thus errors, because of the false.

1 comment

0

Oh lol i'm dumb. I didn't even notice it was working fine

This discussion is preserved as it was. New answers, comments, and votes are closed.