This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

Godot version 3.2.3
in Engine by (23 points)

1 Answer

0 votes

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) ]
by (3,164 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.