✓ Accepted answer
Pcall is a function you can use for creating your own error handler. Pcall will execute a function and will return two values: a bool value to see if the function has successfully ran without any errors, and an error message, if there was an error.
function Func1()
print('Hi')
end
function Func2()
PRint('Hi')
end)
local success1, message1 = pcall(Func1)
local success2, message2 = pcall(Func2)
if success1 then
print('Successfully ran 1st func')
else
print('Failed to run 1st func: '..message1)
end
if success2 then
print('Successfully ran' 2nd func')
else
print('Failed to run 2nd func: '..message2)
end
This script above will print 'Successfully ran 1st func', but will print 'Failed to run 2nd func: error here's
Coroutines are useful for multi-threading. They allow you to execute code at the same time. Coroutines have the same purpose of Spawn()
local coro1 = coroutine.wrap(function()
for i = 1, 10 do
print(i)
wait(1)
end
end)
local coro2 = coroutine.wrap(function()
local i = 1
repeat
i = i+1
print(i)
wait(1)
until i <= 10
end)
coro1()
coro2()
This will run the for and repeat loop at the same time.
I really don't know how you find a similarity between these
3 comments
omae wa mou shindeiru NANI
In what way do you consider this similar.
I mean I use them in a lot of similar ways. It is confusing.....