Verse Library verse

01 Device

Maintains a unique list of team agents and safely adds players without duplicates.

verse-library/adding-additional-team-members/01-device.verse

# This function adds a player to the team list
using { /Verse.org/Simulation }
using { /Fortnite.com/Game }
using { /Fortnite.com/Devices }

# A Verse device that tracks team members
team_manager := class(creative_device):

    # A mutable list that holds every agent on the team
    var TeamMembers : []agent = array{}

    # Checks whether PlayerToAdd is already in TeamMembers
    IsAlreadyOnTeam(PlayerToAdd : agent) : logic =
        # Search the list for a matching agent
        for (Member : TeamMembers):
            if (Member = PlayerToAdd):
                return true
        return false

    # Adds a player to the team list if they are not already on it
    AddPlayerToTeam(PlayerToAdd : agent) : void =
        # First, check if they are already on the team
        if (IsAlreadyOnTeam(PlayerToAdd) = false):
            # If they are not, print a message to the console
            Print("Adding player to the team!")

            # Add them to the list of team members
            set TeamMembers = TeamMembers + array{PlayerToAdd}

Comments

    Sign in to vote, comment, or suggest an edit. Sign in