Godot Version
4.3.0
Question
I’m attempting to implement a stage selection system in my game, but I’m having trouble how to logic out the voting. There is an Autoload called StageManager that, well, manages my stages. It has an array called stages that is full of dictionaries, each dictionary being a stage. These dictionaries include the name, scene, and a preview of the stages.
I want each player (4 total) to be able to vote on any stage in the game, which will be all of the stages that are in this StageManager and in the stages array. When a player votes, their vote gets added to a dictionary that goes player_id : stage_index and it’s replicated across all clients.
Now what I’m having trouble is how to use that dictionary to actually select the stage. I can get all of the votes by themselves using .values(), but then what? The votes will all be in the form of integers since they are in the form of an index from an array. If everyone votes for stage 3, how will I have the function choose stage 3? Or if two people vote for stage 0, and one person votes for stage 1, and one person votes for stage 2, how do I have the function return that stage 2 was chosen?
There’s also the problem of tiebreaking. In the event that two or four maps were voted for equally, I would like to have the function randomly choose from the voted from maps. Is there a built in way to choose a random value from an array?