For coroutines: I’ve considered this as a solution, but unfortunately it’s rather chunky (hard to read and takes up a lot of space), and I’m not sure it’s too performant either. My animations mostly take place in a modulescript, so I’m not sure how coroutines would line up as well
For task.spawn: I couldn’t figure out how to cancel the thread that ran the (replica-)assert function
I’ve attempted to use it, but this is what the code looks like:
function fakeAssert(any: any)
if not any then
task.cancel()
end -- cancel what??
end
function myAnimation(character)
fakeAssert(findAnimator(character)) -- find animator just finds the animator
end
How does fakeAssert terminate the myAnimation thread when it returns false. I’ve attempted to figure out how to specifically cancel it, but couldn’t find out how to actually cancel the myAnimation thread that’s being ran
I’ll probably just end up making a feature request to see what happens, having an assert method without cluttering up the output would be really nice
(Update:… feature requests are beyond my trust level, I guess I’ll have to deal with conditional statements for now…
update 2: aaa it’s all boilerplate it’s like an actual nightmare noooooo)
Use pcall at the start of your script to prevent from any type of errors
Example :
local suc,err = pcall(function()
if game.NotLighting == true then
-- Your script
end
end)
you can check why it errors or if its successful and has no errors at all by doing this
Example :
local suc,err = pcall(function()
if game.NotLighting == true then
-- Your script
end
end)
print(suc) -- if its true then its successful otherwise it has errors
print(err) -- this prints the reason of the error if its nil then it means there is no error
function demand(condition: any): any
if condition then
return condition
else
task.defer(coroutine.close, coroutine.running())
coroutine.yield(coroutine.running())
return nil
end
end
demand(2 == 1)
print("test") -- "test" will not be printed, because the demand statement above returned false, which terminated the thread -- without an error!