How can I detect the status of a coroutine? ]

Just how can I detect the status of a coroutine?.. :woman_shrugging:

This code gives me an error

if coroutine.status(DaBroCoroutine) == "suspended" then
	print("Hey bro! I'm suspended")
end

ERROR: invalid argument #1 to ā€˜status’ (thread expected, got nil) -

cb7b22daf74a964036c80c555c649259

Try searching in Enum. to see if there was status for the coroutines but I didn’t find any
(Neither in the Devforum)

1 Like

The returned status is indeed a string, the error you are getting means the DaBroCoroutine var is nil.

As a reminder you should create coroutines like this:

coro = coroutine.create(function)
--coro is now our thread
print(coroutine.status(coro)) -- prints "suspended"

3 Likes

I already did print and that’s why I put suspended because that’s what it printed
My question is how do I detect it in an if statement?

You’re code is right,

print(coroutine.status(coro) == "suspended") --Prints true if the coroutine is suspended

We can verify this by printing the type of what the status method returns:

print(typeof(coroutine.status(coro))) -- string
1 Like

You are right, my code is fine!
My error was due to something else in my code that still didn’t make the value of ā€œDaBroCoroutineā€ a coroutine.

Srry! :sweat_smile:

2 Likes