Bully-Board

Bully Modding Section => Modding Questions/Help => Topic started by: RBS ID on January 20, 2022, 07:23:36 PM

Title: What is Coroutine?
Post by: RBS ID on January 20, 2022, 07:23:36 PM
Does anyone know, what is Coroutine?
Title: Re: What is Coroutine?
Post by: Altamurenza on January 21, 2022, 02:17:16 AM
It's simply a thread, provided by Lua in order to do multithreading.

In Bully, we have CreateThread function that works pretty much like coroutine (https://www.lua.org/pil/9.html). But, CreateThread function does not provide any information about status of the thread itself, so we don't know exactly as if the thread is already dead or not. Unless you made a continuous running function or inconstant variable that changes every run in the loop just to check the thread status.

On the other hand, coroutine has coroutine.status function which returns a state of coroutine (unlike CreateThread). But, coroutine function does not run independently as CreateThread function does, which means you also need a bigger space to operate that thing.

However, this explanation is just a simple logic comparation between CreateThread and Coroutines. I personally use coroutine function just for making infinite loop of "potential crash infinite loop", so it can restart once it crashed. What if i was pretty sure it won't crash? then i would prefer to use CreateThread instead.
Title: Re: What is Coroutine?
Post by: Razc01na on January 21, 2022, 08:41:32 AM
Are coroutine based functions available in the game?
Title: Re: What is Coroutine?
Post by: Altamurenza on January 21, 2022, 09:26:12 AM
Are coroutine based functions available in the game?

Yes, they are.

If you curious about any function existence, you can just check it by the game.
Code: [Select]
if IsButtonBeingPressed(3, 0) then
  TextPrintString(tostring(type(coroutine.create)), 4, 1)
end