Failure in the right operand of 'set ... = ..." is not yet implemented error in Documentation Team Balancing code

The error message above relates to the .Length part of the code? Why is this happening and how can I fix it? Any help would be appreciated

BalanceTeams() : void =
AllPlayers := GetPlayspace().GetPlayers()
for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
# Assign Players to a new team if teams are unbalanced
var TeamSize:int = 0

            if(set TeamSize = GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length):
                Print("Size of this player's starting team is {TeamSize}")

This is because now you can’t set a variable directly on something that might fail.

eg. set MyNumber=1 will work BUT something like eg. set MyPlayer=Players[0] won’t because while most likely there’s a player on the 0 position of that list the code can’t be sure, that’s why you add an extra if

from set MyPlayer=Players[0] it becomes:

if(ActualPlayer:=Players[0]):
   set MyPlayer=ActualPlayer

In your case it becomes

if(TheSize:=GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length):
        set TeamSize=TheSize
        Print("Size of this player's starting team is {TeamSize}")

ah, thanks! it doesnt give an error anymore, but still need to test it. Will follow up after testing it. Thank you for the response!

hm, it doesnt seem to work. i don’t believe its the fixed code, but just the code in general. I don’t know if it’s because it’s outdated, or if it simply just doesnt work. We have the exact same code besides the slight change to fix the error. Their Join In Progress code for balancing teams doesn’t work and on game start, if im by myself, i’ll spawn on team 1 spawners but then be set on team 2. Overall the code doesn’t seem to work well. Thank you anyways for the quick response though! Maybe we can figure smt else out

could you send the entire code?

Sure!

team_multiplayer_balance := class(creative_device):
    # Holds the teams found with GetTeams()
    var Teams : []team = array{}
    OnBegin<override>()<suspends> : void =

        Print("Verse Device Started!")
        set Teams = Self.GetPlayspace().GetTeamCollection().GetTeams()
        AllPlayers := GetPlayspace().GetPlayers()
        #Subscribe to PlayerAddedEvent to allow team rebalancing when a new player joins the game
        Self.GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
        Print("Beginning to balance teams")
        BalanceTeams()

    #Handles a new player joining the game

    OnPlayerAdded(InPlayer : player) : void =
        Print("A new Player joined, assigning them to a team!")
        BalanceTeams()            

    <#
    For each player, find the number of players of the team they're on. Iterate through the
    list of teams and assign them to the team with the least amount of players, or their
    starting team in case of ties.
    #>

    BalanceTeams() : void =
        AllPlayers := GetPlayspace().GetPlayers()
        for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
            # Assign Players to a new team if teams are unbalanced
            var TeamSize:int = 0

            if(TheSize := GetPlayspace().GetTeamCollection().GetAgents[CurrentTeam].Length):
                set TeamSize = TheSize
                Print("Size of this player's starting team is {TeamSize}")

            SmallestTeam : ?team = FindSmallestTeam(TeamSize)
            if (TeamToAssign := SmallestTeam?, GetPlayspace().GetTeamCollection().AddToTeam[TeamPlayer, TeamToAssign]):
                Print("Attempting to assign player to a new team")

    FindSmallestTeam(CurrentTeamSize : int) : ?team =
        var SmallestTeam : ?team = false
        var TeamSize : int = CurrentTeamSize

        <#
        For each team Team, get the number of players on that team. If it has less players than SmallestTeam,
        set SmallestTeam to Team and update TeamSize to the number of players on the new Team
        #>

        for(Team : Teams, CandidateTeamSize := GetPlayspace().GetTeamCollection().GetAgents[Team].Length, TeamSize > CandidateTeamSize):
            set SmallestTeam = option{Team}
            set TeamSize = CandidateTeamSize
            Print("Found a team with less players: {CandidateTeamSize}")
        return SmallestTeam

Why is this not possible? If Players[0] fails, the failure context would just rollback everything so the set wouldn’t matter anyways, right?

Logically yes but clearly there is some complications or something with doing things that way and thus it wasn’t allowed can’t really do much unfortunately