Assert finds an index that doesn't exist?

the title explains it all

an if statement does the job perfectly with no errors nor anything

if FailedModuleScriptsInfo[module_script:GetFullName()] then
	error("[Provenance."..module_script.Name.."]: "..FailedModuleScriptsInfo[module_script:GetFullName()])
end

the following assert though…

assert(
	not FailedModuleScriptsInfo[module_script:GetFullName()],
	"[Provenance."..module_script.Name.."]: "..FailedModuleScriptsInfo[module_script:GetFullName()]
)

it uh. uhm… it does this

my brain is currently boiling so any help is appreciated

Assert does not find an index that doesn’t exist. The first argument you give to assert is true (not nil == true) as it should be which means assert is not going to throw an error with the given error message. As you can see from the error message you got, it’s not your own error message. The error is caused by FailedModuleScriptsInfo[module_script:GetFullName()] being nil. When calling assert, both arguments are evaluated. Thus, the error message given to assert is evaluated regardless of the value of the first argument. So even if the error message is not going to be used, it is still evaluated, and in your case, the evaluation errors.

I’d recommend just using the if statement.

1 Like

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