# How to subscribe to TriggeredEvent?

**URL:** <https://forums.unrealengine.com/t/how-to-subscribe-to-triggeredevent/1752007>\
**Category:** Programming & Scripting\
**Tags:** fortnite-creative, unreal-editor-for-fortnite, question, fortnite\
**Created:** [March 14, 2024, 6:36pm UTC](https://forums.unrealengine.com/t/how-to-subscribe-to-triggeredevent/1752007 "2024-03-14T18:36:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BraveGamerTV](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bravegamertv/32/638877_2.png) [@BraveGamerTV](https://forums.unrealengine.com/u/BraveGamerTV)\
**Post date:** [March 14, 2024, 6:36pm UTC](https://forums.unrealengine.com/t/how-to-subscribe-to-triggeredevent/1752007/1 "2024-03-14T18:36:29Z")

</div>

It returns error `This function parameter expects a value of type ?agent->void, but this argument is an incompatible value of type type{_(:[]char)<suspends>:void}.`

```auto
using { /Fortnite.com/Devices }
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
MapLoader := class(creative_device):

    @editable
    CC:trigger_device = trigger_device{}

    @editable
    MapText:billboard_device = billboard_device{}

    @editable
    DifficultyText:billboard_device = billboard_device{}

    var initseconds : int = 0

    @editable
    StartTimer:billboard_device = billboard_device{}

    @editable
    RNG:rng_device = rng_device{}

    @editable
    InitTimerInit:trigger_device = trigger_device{}

    StringToMessage<localizes>(value:string)<computes> : message = "{value}"

    OnBegin<override>()<suspends>:void=
        Print("Script started")

        MapText.SetText(StringToMessage("Waiting for player(s).."))
        DifficultyText.SetText(StringToMessage(" "))
        StartTimer.SetText(StringToMessage("{initseconds}s"))
        Print("Defaults set")
        

        InitTimerInit.TriggeredEvent.Await()
        Print("I saw a TriggeredEvent")
        set initseconds = 10
        Print("initseconds set")
        loop:
            if (initseconds > 0):
                set initseconds = initseconds - 1
                Sleep(1.0)
                StartTimer.SetText(StringToMessage("{initseconds}s"))
                Print("{initseconds}")
            else:
                StartTimer.SetText(StringToMessage("{initseconds}s"))
                Print("Done")
                RNG.Activate()
                CC.TriggeredEvent.Subscribe(OnTriggeredEvent)
                break

OnTriggeredEvent<private>(Reading : string)<suspends>:void=
    MapText.SetText(StringToMessage("Castaway Castles"))
    DifficultyText.SetText(StringToMessage("EASY"))

```

---

<div class="post-metadata">

**Author:** ![bananna\_manuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bananna\_manuk](https://forums.unrealengine.com/u/bananna_manuk)\
**Post date:** [March 14, 2024, 7:01pm UTC](https://forums.unrealengine.com/t/how-to-subscribe-to-triggeredevent/1752007/2 "2024-03-14T19:01:51Z")

</div>

CC.TriggeredEvent.Subscribe(myFunction)

this will send the agent which triggered cc to MyFunction

---

<div class="post-metadata">

**Author:** ![dragonflii](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dragonflii](https://forums.unrealengine.com/u/dragonflii)\
**Post date:** [March 14, 2024, 7:06pm UTC](https://forums.unrealengine.com/t/how-to-subscribe-to-triggeredevent/1752007/3 "2024-03-14T19:06:43Z")

</div>

> [@BraveGamerTV](#):
>
> ```auto
> OnTriggeredEvent<private>(Reading : string)<suspends>:void=
> MapText.SetText(StringToMessage("Castaway Castles"))
> DifficultyText.SetText(StringToMessage("EASY"))
> 
> ```

The error describes the problem. The handler function signature must match what the event expects. Like so:

```auto
OnTriggeredEvent<private>(Agent: ?agent):void=

```

(Note that `<private>` is only allowed inside a class - watch indents.)  
If you want to pass extra data to the handler, you can use a wrapper (similar code is available in the snippets section.)

```auto
(Listenable : listenable(?agent)).SubscribeAgentVoid(Out : tuple(?agent, t)->void, MyData : t where t:type) : cancelable =
  Wrapper := wrapper_agentvoid(t){MyData := MyData, Out := Out}
  Listenable.Subscribe(Wrapper.In)

wrapper_agentvoid(t : type) := class():
  MyData : t;
  Out : tuple(?agent, t) -> void
  In(Agent : ?agent):void = Out(Agent, MyData)

```

Which you could then use like this:

```auto
TriggerCancelable : cancelable = Trigger.TriggeredEvent.SubscribeAgentVoid(OnTriggeredEvent, "Your String")

```

Or check this out:

[Guide to Event Subscribing with Additional Parameters (Handler Functions) - Programming & Scripting / Verse - Epic Developer Community Forums (unrealengine.com)](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925)
