Coroutines & Minigames?

I’m not sure what the best way for making minigames with lobbies inside them for a gamemode so I asked a friend. He suggested that I use coroutines, but I can’t figure out how to use them in this situation. I have never touched coroutines, so I am requesting an example/explanation of what to do here.

I don’t see how coroutines would help any.

Coroutines are a kind of multithreading (although it has nothing to do with multithreading if you ask me) aka collaborative multithreading. They are useful for operations that might last long, like downloading files. You can initiate the download and switch coroutines to do something else while waiting.
They are completely useless in your case though.

Then what would be best for running lobbies with the same minigame, along with other minigames?

A lobby gamemode would simplify everything where you could have seperate entities for each game. But if you really want a lobby(why have a lobby w/o networking?) you’d probably just use a state machine.

The best way to explain coroutines are like ‘somewhat kind of threads’ I suppose. Basically it’s like a new lua state, all the code in the coroutine will run completely seperate from the rest of the lua, however it’s still on the same thread.

By the way coroutines are broken in GM12. They’re fixed in GM13 though.

Can someone explain state based machines please.

The graphics help.

So how would I do that in garry’s mod lua :L?

In Garry’s Mod, you basically use hooks. Lots of them. They are called in specific events/times. Imagine Player A is playing PVP. If the hook PlayerDeath is called with Player A as a killer, then give him a point, for example. It’s mostly like this.

Don’t over complicate it.

Just use different lobbies and store each minigame’s variables and whatnot in seperate tables…
When you need to do calculations per-minigame just loop through and do it per minigame.

If you don’t know any lua, this might be kinda difficult for you.