Be careful when using assert() and Why

Just to be 100% sure, assert is fine to use as long as you don’t concatenate a string in the second argument?

Good:

assert(false, "Something went wrong!")

Bad:

assert(false, "Something went wrong for"..player.Name.."!")

?

2 Likes

yes, you are correct. You understood it very well.

2 Likes

For this purpose make your own assert with a formatter.

1 Like

Assert with concatenation is fine to use in most scenarios. If you’re running assert many times per frame that’s when it can become an issue.

A natural way to avoid assert in both scenarios is using guard clauses.

if false then
    error("Something went wrong for " .. player.Name .. "!")
end

Use guard clauses over assert or custom-assert modules.

2 Likes