News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: What is Coroutine?  (Read 1363 times)

0 Members and 1 Guest are viewing this topic.

Offline RBS ID

  • Jr. Member
  • **
  • Posts: 67
  • Gender: Male
  • I don't know.
    • View Profile
    • This is website title.
What is Coroutine?
« on: January 20, 2022, 07:23:36 PM »
Does anyone know, what is Coroutine?

Offline Altamurenza

  • Full Member
  • ***
  • Posts: 118
  • Gender: Male
  • I love cheat, unique, realistic, & expansion mod.
    • View Profile
Re: What is Coroutine?
« Reply #1 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. 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.
« Last Edit: January 21, 2022, 02:23:52 AM by Altamurenza »

Offline Razc01na

  • Lord Slayer
  • Full Member
  • ***
  • Posts: 156
  • Gender: Male
  • Doom is life
    • View Profile
Re: What is Coroutine?
« Reply #2 on: January 21, 2022, 08:41:32 AM »
Are coroutine based functions available in the game?

Offline Altamurenza

  • Full Member
  • ***
  • Posts: 118
  • Gender: Male
  • I love cheat, unique, realistic, & expansion mod.
    • View Profile
Re: What is Coroutine?
« Reply #3 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