How do I add custom events in verse creative devices?

I have a device that handles all gameplay logic for my game mode, and I have a storm controller in my level that I want to generate whenever something is triggered in that device. How do I add a custom event like what is seen in other creative devices?

Storm Controller

image

I want to be able to select an event from this dropdown which will then generate the storm.

Score Manager Example

Verse (Digest script):

MaxTriggers<public>:listenable(agent) = external {}

Verse (Custom creative device script):

var ScoreManager : score_manager_device = score_manager_device{}
ScoreManager.MaxTriggers.Subscribe(Func)

Editor:

image

3 Likes

Thanks for the feedback, this is something that is being considered, I passed this on to the dev team.

2 Likes

Could you simply expose an event variable in your device and call Signal() on it when it is triggered? It might not be exactly the same, though it should have essentially the same functionality. An example is in the Space Inside / Escape Room showcase.

3 Likes

How do you expose an event variable? Like this?

MyEvent<public>():event()

If so, I get this error:

Non-abstract class cannot declare abstract function `MyEvent`.(3591)

You’re missing the right-hand side:

MyCustomEvent<public> : event() = event(){}

Once you’ve added the above, you’ll be able to signal the event using

MyCustomEvent.Signal()
2 Likes

That fixed the error, thanks. However you can’t select it from the dropdown box from another device function. I am misunderstanding these events or is there something else I’m missing?

Storm Controller

image

You can’t create an editable storm controller variable so I can’t subscribe to it via Verse, only through these functions.

EDIT:

I am also getting this error when trying to signal the event

Unknown member `Signal` in `tuple()->event(tuple())`.(3506)
2 Likes

It would be nice if anyone can provide a fully working step by step example of how to use custom events and Signal() since we don’t fully understand how we should approach it.

The tutorial on creating a countdown timer shows you how you can set up events. In the tutorial you set up an event and signal it when the countdown ends.

3 Likes

So you can only use events in other custom Verse creative devices and cannot be used in the dropdown boxes for existing creative devices?

1 Like

I’m having the same issue. Can’t get any of my events or functions to show up in the device options for linking.

From what I understand this functionality is not available. At least for now. You can create a custom event in your code, you can send it using Signal(), you can listen for it in any other custom device’s code using Await(), but you can’t access it from default creative devices (again, at least for now).

1 Like

Any update on this? Would be really great to have this implemented.

2 Likes

Thanks for that example @wxyz it wasnt exactly what i was having issues with but it put me on the path to find a work around so muchly appreciated!

Just to clarify because it maybe its still solvable without the workaround. As an example if i have an item spawner and i want to bind Enable() to an event on a custom creative device i can’t seem to do that as no events show up in the drop down.

I found a workaround on this post:

This is my implementation of a player manager that listen to Spawn Pads and dispatch to subscribers…

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

SpawnerTag := class(tag){}

players_subscribable_type := type{_(:agent):void}
players_subscribable := class:
    var Subscribers<private>:[]players_subscribable_type = array{}
    Subscribe<public>(Sub:players_subscribable_type):void =
        set Subscribers += array{Sub}
    Dispatch<public>(Player: agent):void =
        for (Sub:Subscribers):
            Sub(Player)

players_manager := class(creative_device):
    var PlayerSpawners : []player_spawner_device = array{}
    var Players : []agent = array{}
  
    OnBegin<override>()<suspends>:void=
        Print("Hello, Players!!")
        # Get all the spawners
        var TaggedSpawners : []creative_object_interface = GetCreativeObjectsWithTag(SpawnerTag{})
        for (TaggedSpawner : TaggedSpawners, Spawner := player_spawner_device[TaggedSpawner]):
            set PlayerSpawners = PlayerSpawners + array{Spawner}
            # Subscribe to each player spawn pad
            Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn)
   
    OnPlayerSpawn(SpawnedPlayer : agent) : void =
        Print("A Player just spawned!")
        set Players = Players + array{SpawnedPlayer}
        # Emit event for subscribers
        PlayerSpawnedEvent.Dispatch(SpawnedPlayer)

    # Custom event
    var PlayerSpawnedEvent<public>:players_subscribable = players_subscribable{}
7 Likes