How can I add a scoreboard to my game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toshnewton

I am very new to Godot and I believe given enough time I could figure out how to make a scoreboard that features just 2 people. But I want to have a scoreboard that can track from 2 to 8 players.

Below is my code:

Any and all help is very much appreciated.

:bust_in_silhouette: Reply From: Ertain

How about have a dictionary which keeps track of the player scores? Each key of the dictionary corresponds to the player, i.e “player1”, “player2”, “player3”, and so on. When the players score, the points are added to the entries in the dictionary. The scoreboard can access the values of each player by their keys. For instance, some scoreboard with Control nodes could access the dictionary like this:

## This code is untested; use at your own risk! ##
# The dictionary which holds the scores.
var player_scores: Dictionary = {
    "player1" : 0, "player2": 0, "player3": 0
# Some function down the page.
func _update_scores():
    for count in range( player_scores.keys().size() ):
          # Access some text field (like a label) in the scoreboard and assign the player score.
          get_node( "player" + str(count + 1) ).text = player_scores[ "player" + str(count + 1) ]