Brave.
Brave.

Reputation: 33

How to subscribe to TriggeredEvent in trigger_device?

I want to be able to show text on a billboard device once my program sees CC.TriggeredEvent however it seems to have problems when subscribing to type ?agent->void. Any solutions?

The error returned on CC.TriggeredEvent.Subscribe(OnTriggeredEvent):

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

Code:


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>(Agent:agent)<suspends>:void=
    MapText.SetText(StringToMessage("Castaway Castles"))
    DifficultyText.SetText(StringToMessage("EASY"))

Upvotes: 1

Views: 364

Answers (1)

FabioUEFN
FabioUEFN

Reputation: 21

You're subscribing to a function that has the <suspends> effect specifier which causes that error. Create a new function that uses the spawn{} expression to call OnTriggerEvent. For example:

CC.TriggeredEvent.Subscribe(Start_OnTriggeredEvent)

Start_OnTriggeredEvent(a:agent) : void = spawn{OnTriggeredEvent()}

Upvotes: 2

Related Questions