I’m just curious and confused at the same time when I always see this on a pcall() function, So, I want to know what is difference in the two variables?
-- Is this similiar~
local var1, var2 = value
-- ~To this?
local var1 = value
local var2 = value
--Then why is it use it in pcall() like this?
local var1, var2 = pcall(function()
--Logic
end)
--and getting the argument out of it.
if var1 then
-- logic
else
-- logic
end
Sorry, for this silly question, because I’m used to JS or Java alot when assigning like this is like assigning a similar value to a multiple variables using only a shorter declaration like this.
pcall and some other functions return a tuple. This means it will return multiple values. local var1, var2 = value should make var2 nil, and var1 value, however local var1, var2 = value1, value2 would make var1 equal to value1 and var2 equal to value2.
The first argument, var1, is a bool that returns whether the pcall ran without errors or not.
The second argument is the error message if and only if something errored in the pcall. It is useful for printing the error message yourself and fix your code.