# Trigger and Teleporter array error

**URL:** <https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 29, 2024, 6:07pm UTC](https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439 "2024-04-29T18:07:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TwitchPlaycious](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TwitchPlaycious](https://forums.unrealengine.com/u/TwitchPlaycious)\
**Post date:** [April 29, 2024, 6:07pm UTC](https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439/1 "2024-04-29T18:07:57Z")

</div>

I am trying to make an array of triggers (12) correspond to a teleporter(12)…  
I might be really far off. I am very new to verse.  
so I get this error:

This function parameter expects a value of type agent, but this argument is an incompatible value of type ?agent.(3509)  
Agent:?agent

FULL CODE:

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

# A Verse-authored creative device that can be placed in a level

game\_manager := class(creative\_device):

```
@editable var CE_TELEPORTERS : []teleporter_device = array{}
@editable var CR_TRIGGER : []trigger_device = array{}

# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
    block:
# Function to initialize triggers and setup event subscription
InitializeTriggers() : void =
    for (Trigger : CR_TRIGGER):
        Trigger.TriggeredEvent.Subscribe(TeleportToCE)

TeleportToCE(Agent:?agent) : void = 
    for (teleporter : CE_TELEPORTERS):
        teleporter.Teleport(Agent)

```

---

<div class="post-metadata">

**Author:** ![AuryMcClain](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AuryMcClain](https://forums.unrealengine.com/u/AuryMcClain)\
**Post date:** [April 30, 2024, 3:50pm UTC](https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439/2 "2024-04-30T15:50:44Z")

</div>

> [@TwitchPlaycious](#):
>
> ```auto
> TeleportToCE(Agent:?agent) : void = 
> for (teleporter : CE_TELEPORTERS):
> teleporter.Teleport(Agent)
> 
> ```

Hello!

In this code, teleporter.Teleport expects an agent, but you’re currently passing it an optional agent (?agent).

Just to confirm what the function needs, here is the documentation for teleporter.Teleport:

> **[Teleport function](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/devices/teleporter_device/teleport)**
>
> Learn technical details about the Teleport function.

So, we want an actual agent and we have an optional agent, but what is an option? **An option is a container that either stores a value of that type, or has no value.** Here is some additional documentation on options:

> **[Option](https://dev.epicgames.com/documentation/en-us/uefn/option-in-verse)**
>
> The option type can contain one value or can be empty.

In this case, we have an optional agent. The name of the variable itself doesn’t matter, so I’ll rename it to MaybeAgent, to signify that it might, or might not, contain an actual agent.

```auto
TeleportToCE(MaybeAgent:?agent) : void = 

```

But, we’d like to check “does the option currently hold a value”? If it does, we’ll teleport it. To do this, we’ll use **MaybeAgent?** inside of an if() statement, and try to get an actual agent, like so:

```auto
TeleportToCE(MaybeAgent:?agent) : void = 
    if (Agent := MaybeAgent?):
        for (teleporter : CE_TELEPORTERS):
            teleporter.Teleport(Agent)

```

Notice that we are passing the actual Agent here, and not passing the option, Maybe Agent.

If the if fails, then we do not actually have an agent, and we have nothing to teleport.

---

<div class="post-metadata">

**Author:** ![AuryMcClain](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AuryMcClain](https://forums.unrealengine.com/u/AuryMcClain)\
**Post date:** [April 30, 2024, 3:53pm UTC](https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439/3 "2024-04-30T15:53:06Z")

</div>

Also, I found this video with an in-depth description of how to use options:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/5/1d53b5069840ab3fe58b730cfbb41af20c174c81.jpeg "Why You Should Use Optionals - Verse Programming Language / UEFN Tutorial") ](https://www.youtube.com/watch?v=NwetUZ4TL0Q)

---

<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:** [June 27, 2024, 4:46am UTC](https://forums.unrealengine.com/t/trigger-and-teleporter-array-error/1829439/4 "2024-06-27T04:46:40Z")

</div>

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