• Hey! Register here to create your account, engage with the community, and talk about what is new!

Queue and Ready-Up

ConnorWithoutAnE

New member
Joined
May 21, 2023
Messages
5
Reaction score
0
I am trying to add a Queue system to my game where when everybody is Readied Up the game starts and I have no idea how to. Any suggestions?
 
Solution
Others might have better methods to do this, but I'll tell you a commonly known way, ya could use Lists.

You can also use Dictionaries to achieve this if you really want to keep track of different queue states, such as readied up or inactive, and if you want to use that in-queue information to manage it a little better.

  • → If you want to make a one time ready up for a queue, maybe use Lists
    • Lists are just a collection of different information, each entry is associated with an index
  • → If you want to keep track of different queue states so they can ready, and then unready → use Dictionaries
    • Dictionaries are similar to Lists, except they use keys and values for each and every entry. The key will be the player's...

Refrizor

Retired Administrator
Retired Admin
Joined
Aug 16, 2020
Messages
513
Reaction score
361
Others might have better methods to do this, but I'll tell you a commonly known way, ya could use Lists.

You can also use Dictionaries to achieve this if you really want to keep track of different queue states, such as readied up or inactive, and if you want to use that in-queue information to manage it a little better.

  • → If you want to make a one time ready up for a queue, maybe use Lists
    • Lists are just a collection of different information, each entry is associated with an index
  • → If you want to keep track of different queue states so they can ready, and then unready → use Dictionaries
    • Dictionaries are similar to Lists, except they use keys and values for each and every entry. The key will be the player's UUID, and the value we'd be setting would be the player's queue state such as ready or unready

A: Lists
Here are the main factors that we'll pay attention to and consider:
  • If not familiar, a List is simply a collection of values that are assigned to a variable, such as integers, UUIDs, player names, strings, and so on. You can later use the variable as a reference to remove or modify the list later on
  • You will append (add) a player's UUID to a variable named queue each time the player joins the queue. Likewise, you also need to check if they are currently in the queue or not before appending
  • When the player leaves the queue or quits the game, you will remove the player's UUID from the list
  • Last but not least, each time a player joins the queue, check if the queue count is >= to a certain number of your liking


If you need further assistance:​

  1. I'd use a function specifically for the queue logic that you will call anytime you want to add someone to it. Likewise, a remove function to remove them if you'd like
  2. Next, let's implement the logic for checking if they are in the queue before appending them. Use If variable: List contains value. For the chest parameters, put in the name of the variable, alongside the player's UUID or player name. You can do this by going to Values → Game Value → Informational values → UUID or player name (I'll be using UUID). Put it in the chest after the variable. Now, use your NOT Arrow and click the sign with it, so it will check if your UUID is not in the List
  3. After If variable, use Set variable: Append Value. Place in the variable, and then add in their UUID or player name into the chest
  4. Tada! You are now done! You can then use an else after the first right bracket to let the player know they are already in the queue

Removing the player​

  1. You don't exactly need to check if the player is in the List to remove them, unless you'd like to use that information
  2. So, simply use Set Variable → List Manipulation → Remove List value. Put in the variable, and then the player's UUID or name

Checking if the queue size is >= a certain number​

  1. So, we need to grab the current List size and assign it to a temporary variable. Use Set Variable → List Manipulation → Get List Length. It requires a new Integer variable that you're going to use the list count for the first parameter (so you can name it queueCount for example), and then the current list variable for the second parameter
  2. Now simply use If variable → List Contains Value. Put in the list variable as parameter 1, and for the second parameter, put in the count variable that we used in step one.
  3. After that, put in your logic to start the game! Perhaps you can use the List variable to transfer the values to a new variable for an ongoing game session, and wipe the previous var, and whoever is in List will teleported for example

After that, you're done!

B: Dictionaries
Key UUID, and value would be either active or inactive, or you could make it an integer, 0 for inactive and 1 for active. For my example I used text vars. I would use this if you want the option to "toggle" between ready and unready to avoid creating new lists just for certain states, dictionaries would be useful in that specific case

  1. For the queue in general, let's make sure they aren't in it before adding them. If variable → Dictionary has key, then use the NOT arrow. Place in a var to hold the queue info, I called it queue. For second parameter, I put in the player UUID (Values → Game Value → Informational values → UUID)
  2. Set variable: SetDictionary value. Queue var in first parameter, UUID in the second parameter, and "inactive" in the third parameter if we want it so they aren't ready by default when they join the queue and gotta manually select ready up
Checking if people are ready
  1. Lets say there's a ready up item that you click, and it will set their value to active in the Dictionary. This section goes right after step 2 above. So, the idea is to check if they are in the queue, and if so, set their value to ready using their key (uuid). Simply check if they are in the queue (step 1 from above, except don't use the not arrow), then use Set variable → SetDictionary value. Queue var in first parameter, UUID in second parameter, and "active" in third parameter. This effectively overwrites the value for the player's key, so no need to remove and then add.
  2. We need to check if a certain amount of queue players are set to active before beginning the game. One option is to use simply sift through all the dictionary keys (of everyone) with the "active" value, and increment a new Local variable to keep track of that number, then check if that variable is >= whatever number you want!
  3. You can do this by using a Repeat block, and set it to For each dictionary entry. Place in the parameters (make 2 new local vars - key and value, place them in. This is because the parameter requires these, be sure to look at the parameter criteria. Then for parameter 3, simply place in the pre-existing queue dictionary var!
  4. Add If variable → Dictionary value equals, for parameters place in the normal queue dictionary variable we made earlier on, then place in the new local "key" variable we just created for the for loop, and then for parameter three, place in the "active" value.. make sure this is the value that you were setting earlier.
  5. Then, add a Set variable → Numerical actions → Increment number (+=). Make a new "count" variable, place it in parameter one. What we are doing is sifting through all the keys with the value "active" and then adding a new local variable to increment each time that returns true.. so if there's 5 people in the dictionary with the active value set, it increments five times
  6. Now, outside the loop, you can use If var → Number >=, place in the count variable, and then place in a number for how many active queue players you want before starting the game. Then, simply add the logic in after that!:)

But yeah I hope it helps! If this didn't solve your question, feel free to say so and another member might be able to simplify it and give different methods, there genuinely might be easier ways, but I only personally used lists/dictionaries because of the flexibility with managing that information, so it really depends on your needs
 
Last edited:
Solution

Refrizor

Retired Administrator
Retired Admin
Joined
Aug 16, 2020
Messages
513
Reaction score
361
Where do I get "inactive"?
When you add them to the dictionary if they don’t already exist, you can set their value to inactive if you want them to have to use the ready up system in order to be ready. You use the Set Dictionary from Set Variable, then the parameters will mention that you need a value after their key (uuid), you can add a text var (/txt) that says inactive. You can also use numbers if you’d like for the value instead of “inactive” if you wanna keep track of the states with numbers instead of text.

You can set also set it to active if you’d like, if you prefer it to auto-ready them. But basically you just add a text to the value parameter of set dictionary. Then when you use the ready up item to unready you can use set dictionary (queue, uuid, “inactive”), or to active if they are already inactive. I hope this makes sense! Feel free to ask away if you are confused or need help
 

Refrizor

Retired Administrator
Retired Admin
Joined
Aug 16, 2020
Messages
513
Reaction score
361
If you want it so when they join the plot it activates the code, you’ll put the code after the player join event, I’d personally put the code in a function and call it within the join event, so if not in dictionary, add them, then whenever they ready up do the logic to check if there’s a certain number of players that are active and to set their new state

If you have to use or click an item to actually play the game, you would just use the dictionary code after whatever player event. Example, right click event -> isHolding -> the play game object, then add them to dictionary, give the ready up item, etc.

For setting if you’re ready or not, for example by using a ready up object, use the right click player event, check if they are holding the object, then check if the player is set to inactive, if so, set dictionary value to active, then vice versa, then do the logic for checking if theres x amount of active players (if they set themselves to active). This section doesn’t take place before or after the other dictionary code, it’s an isolated check, the other code is rather just for setting the vars needed such as adding them to the dictionary when they join the game
 
Last edited:
Top Bottom