the users who click on the play button, the username of that particular user is added to list in the firebase in the WaitingUsers tag. and if the tag has at least two users or more then how do i match them randomly? here my user name is Smith
How do i do it?
i m not getting the logic that when players click on play btn they added to waitingusers list. And if there at least two users then they get the match. If there are more than two users(say 100) then how they get match?
Store all users in an array, and create a second project bucket that contains matched pairs / users selected so far. in the app, select your array number and a random array number not in the list of matched pairs. When this is done, add the new matched pair to the matches project bucket. When game over, remove from matches list.
pls sir help me with blocks.. i am trying trying from yesterday but not getting the proper block. so i used another method that is using collintree list view. the users who are online will show in the listview then after element click i have done this.( i have used two collintree listview) pls check it out and give some ideas and sir pls suugest some blocks that are u said before
i asked ChatGpt to help me to match players from a list in firebasae. he is the result i got
If you want the randomly chosen player to be matched with the current player, you can modify the code to remove both the current player and the chosen player from the list. Then, display the matched players' names accordingly. Here's an updated version of the code:
blocks
// Assuming "onlinePlayersList" contains the list of online players ["Player 1", "Player 2", "Player 3", "Player 4"]
var currentPlayer = "Player 1"; // Replace with the name of the current player
// Remove the current player from the list
var modifiedPlayerList = onlinePlayersList.filter(function(player) {
return player !== currentPlayer;
});
if (modifiedPlayerList.length >= 1) {
var randomIndex = Math.floor(Math.random() * modifiedPlayerList.length);
var matchedPlayer = modifiedPlayerList[randomIndex];
// Remove the matched player from the list
modifiedPlayerList.splice(randomIndex, 1);
// Remove the current player from the list
modifiedPlayerList = modifiedPlayerList.filter(function(player) {
return player !== matchedPlayer;
});
// Display the matched players' names
var resultElement = document.createElement("p");
resultElement.innerHTML = "Matched players: " + currentPlayer + " and " + matchedPlayer;
document.body.appendChild(resultElement);
}
how do i implement this block ? i m confused, need help