31.05.2022, 09:52
stat, err are assigned to what the function returns. Since your function does not return anything stat and err are nil and you get empty "error" entry in Logs.
Use this example and put your actual script code inside of the scriptfn function. In the current state this example will simply block execution of any other instances of the same script for 10 seconds. It will also propagate any errors from scriptfn so they are visible in the Error log.
Use this example and put your actual script code inside of the scriptfn function. In the current state this example will simply block execution of any other instances of the same script for 10 seconds. It will also propagate any errors from scriptfn so they are visible in the Error log.
Code:
require('sem')
function scriptfn()
log('script start')
os.sleep(10)
log('script end')
end
stat, err = sem.runlocked('eventlock', 0.1, function(lockres)
if lockres then
return pcall(scriptfn)
else
return nil, 'lock failed'
end
end)
if not stat then
error(err)
end