How to get team scores? from score manager? code example.

Is there a way to get the team total scores, or at least the amount that is output from the Scoremanager?

Current code, but I don’t think I’m on the right track…

     OnBegin<override>()<suspends>:void=
         BlueScoreManager.ScoreOutputEvent.Subscribe(OnBlueScoreOutput)        
         
     OnBlueScoreOutput(Agent: agent):void=
         Print("Blue Score!")

I’m trying to do something similar and hitting some issues.
Basically I make an array of teams, then get an array of all agents of that team, take the first player of the team and look at their score (because I have it set to team score). So far everything seems ok, but in the gameloop checking the score throws errors that I’m not sure how or why. needs a fallback, but I got a bit confused on how that works exactly.

@editable var ScoreMan : score_manager_device = score_manager_device{}
var Teams : []team = array{}

GetTeamScore(TeamID : int)<decides><transacts> : int=
        tempTeam := Teams[TeamID]
        TeamPlayer := GetPlayspace().GetTeamCollection().GetAgents[tempTeam]
        teamPlayerFirst := TeamPlayer[0]
        score := ScoreMan.GetCurrentScore(teamPlayerFirst)
        return score

GameLoop()<suspends> :void=
        loop:            
            if (GetTeamScore[0]):
                Print("Player Score: {GetTeamScore[0]}") # fails here
            else:
                Print("No valid Player")
                return

To get the team’s total score, you’ll want to add up the scores of each player on the team, like @winterdreams suggested.

This is because you are trying to read the value again but not within a failable context, i.e. GetTeamScore[0] doesn’t guarantee a value will return so you need to handle that possibility. Failure documentation link. You’re already handling it on the line before, and what you will want is to store the value you read back from GetTeamScore before using it:

GameLoop()<suspends> :void=
        loop:            
            if (Score:int = GetTeamScore[0]):
                Print("Player Score: {Score}")

You probably don’t want to do this every update tick though, and can use the ScoreOutputEvent like in the OP.