What's better way of having rounds?

I have a round that can take any amount of time to complete (not set on a timer)

What’s the best way of making the rounds.

  1. Use while true loop and yield until various events happen to make it loop again
  2. Better approach

Something tells me the first option is a naive approach and can be hard to maintain and scale.

How would a game like arsenal which has rounds that can take any amount of time to complete do it?(pretty sure it’s not a while loop)

Since the rounds depend on “things happening” (events), I’m thinking the rounds should be based on state. Example event gets fired, checks state to see if in round, does action (end round, etc)

Anyway if someone can tell me the non-naive approach thanks. (also how does RunService tie in? is that only for timers?)

you can do:

repeat wait() until --insert condition for the script to continue / for the round to end here–

BoolValue which represents if a round is in progress or not, when it’s changed detect if it’s changed to true/false and act accordingly (if false start new round), (if true then round has just begun).

That’s the same as option 1. I’m asking if there is a better approach.

@Forummer you are basically saying have rounds as “state” and when events fire read the state of the round and act accordingly?

I don’t really know what I am saying, I just want to know how a game like arsenal manages their rounds

I would recommend using events to detect when a round is over.

I can’t be any more specific because I’m not sure what your game/rounds are about. But, an example would be detecting when all players except 1 have been KO’ed. You would check how many players are left every time a player gets KO’ed, and if the remaining number of players is <= 1, you would end the round, do you intermission, and start the next round. I scripted a round based game that used this philosophy and it seemed to work pretty well.

So basically everyone is saying “state/event based round system”

The thing is using events and state can cause the need for a lot of global variables (isRoundActive, playersInRound, any data id need to know when an event fires)

You don’t necessarily have to use global variables. Let’s say you have three high level functions: startRound, endRound, and intermission. startRound starts the round, endRound ends the round, and intermission is your in-between rounds time that could include map voting, etc.

To make the flow of logic circular, endRound will call intermission, and intermission will call startRound. The only thing you’re missing is startRound calling endRound. That’s when you use the event instead of startRound to call endRound. And there you have it, no global variables required!

1 Like

Okay good idea!

You could probably also put the intermission at the beginning or startRound or end of endRound.

Also I want the code execution to be as linear as possible (pretty sure the pros say linear is better cuz easier to keep track)

Okay thanks! I will try this out and see what I come up with.

1 Like