It’s a function you can use to manually throw errors in your code. If the given condition is false, it will error with a custom message.
assert(true, "Error message")
--> No errors will be thrown
assert(false, "Error message")
--> An error will be thrown with the text "Error message"
Here’s an example of how this might be useful:
local function doSomethingWithANumber(number)
assert(type(number) == "number", "Argument 1 must be a number")
end
Which does the same thing as:
local function doSomethingWithANumber(number)
if type(number) ~= "number" then
error("Argument 1 must be a number")
end
end
This is helpful when you want to validate/test your code, as issues you have can be found and fixed (as they are errors, they are super obvious when they occur).