# Get Agent of the first and second team for Color changing device

**URL:** <https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [August 13, 2023, 6:28am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431 "2023-08-13T06:28:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasanth.akon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@prasanth.akon](https://forums.unrealengine.com/u/prasanth.akon)\
**Post date:** [August 13, 2023, 6:28am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/1 "2023-08-13T06:28:09Z")

</div>

I want to add a timed feature for color-changing devices that set the team back and forth using the SetTeam function. I got the player’s agent using the below code, but I want to get the other team’s Agent to switch dynamically. Any idea on how to implement this?

```auto
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }

using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
ReactiveColorFloor_device := class(creative_device):
    @editable var ColorFloorTiles : []color_changing_tiles_device = array{}
    # Runs when the device is started in a running game
    var Team : []team = array{}
    var Alternate : logic = false
    OnBegin<override>()<suspends>:void=
       # TODO: Replace this with your code
        for (Row := 0..ColorFloorTiles.Length - 1):
            if (Tile := ColorFloorTiles[Row]):
                if:
                    FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
                    MyAgent := FirstPlayer.GetFortCharacter[].GetAgent[]

                then:
                    Tile.SetTeam(MyAgent)
                    

```

---

<div class="post-metadata">

**Author:** ![Twin01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twin01/32/1077777_2.png) [@Twin01](https://forums.unrealengine.com/u/Twin01)\
**Post date:** [August 13, 2023, 7:36am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/2 "2023-08-13T07:36:02Z")

</div>

you can store the last agent in a variable itself, you would most likely have to store it in an optional variable like this:

`var MaybeLastAgent: ?agent = false`

and then set it like this `set MaybeLastAgent = option{Agent}` each time it gets switched over.

You can access an optional variable like this `if (LastAgent := MaybeLastAgent?):` and then do stuff with `LastAgent`.

---

<div class="post-metadata">

**Author:** ![prasanth.akon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@prasanth.akon](https://forums.unrealengine.com/u/prasanth.akon)\
**Post date:** [August 13, 2023, 7:40am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/3 "2023-08-13T07:40:40Z")

</div>

Hi Thomas,  
Thanks for your reply. This takes care of setting the agent, but how would I get the second team’s agent?  
For example, this code gets the Agent of the first player. Similarly I need to get the Agent of Team 2,3,etc…

```auto
 if:
                    FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
                    MyAgent := FirstPlayer.GetFortCharacter[].GetAgent[]

                then:
                    Tile.SetTeam(MyAgent)

```

---

<div class="post-metadata">

**Author:** ![Twin01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twin01/32/1077777_2.png) [@Twin01](https://forums.unrealengine.com/u/Twin01)\
**Post date:** [August 13, 2023, 8:51am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/4 "2023-08-13T08:51:48Z")

</div>

I guess I’m sort of confused by the actual progression of this game mechanic, but basically you’re able to store any amount of agents you want that way, and if you need you could do it in an array where it keeps track of them in a specific order, etc.

---

<div class="post-metadata">

**Author:** ![prasanth.akon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@prasanth.akon](https://forums.unrealengine.com/u/prasanth.akon)\
**Post date:** [August 14, 2023, 12:07pm UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/5 "2023-08-14T12:07:30Z")

</div>

Hi @Twin01,  
Thanks for your reply. What I’m trying to achieve here is portrayed in the following image

 ![WhatsApp Image 2023-08-14 at 17.29.12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/3/a737ebb3055f5d8df33f7d985895541f1cb3c639.jpeg)

Using color-changing devices, I want the platforms to change Or SetTeam() to their respective team color so only they can activate it and get points.

The problem here is really how do I get both the Blue and Red Team’s Agent via verse code? If you guide me to a proper syntax it would be helpful.

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [August 15, 2023, 11:42am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/6 "2023-08-15T11:42:53Z")

</div>

Hey, sounds like [GetAgents function](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/teams/fort_team_collection/getagents) on [fort\_team\_collection interface](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/teams/fort_team_collection) might be what you want.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 14, 2023, 11:43am UTC](https://forums.unrealengine.com/t/get-agent-of-the-first-and-second-team-for-color-changing-device/1259431/7 "2023-09-14T11:43:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
