How do I unsubscribe from a player event?

How do I unsubscribe from an event on a specific element?

Right now I have subscribed to the control change event of a capture area. Later I want to reset that capture area so it can be captured by the same team again, but when I reset the capture area it calls the subscribed event, which throughs everything into disarray. If I can just cancel the subscription between capturing and resetting the capture area everything should work.

1 Like

When you call Subscribe on any device events they will return a cancelable which you can subsequently call Cancel() on to terminate the subscription.

hello_world_device := class(creative_device):

    @editable CaptureArea:capture_area_device = capture_area_device{}

    var ControlChangeSubscription:?cancelable = false

    OnBegin<override>()<suspends>:void=

        set ControlChangeSubscription = option{ CaptureArea.ControlChangeEvent.Subscribe(HandleControlChange) }

        # Do whatever logic you like then cancel
        if (Subscription := ControlChangeSubscription?):
            Subscription.Cancel()
12 Likes

Do you know why I am getting this error and how I could get around it?

The EliminatedEvent is a function so you would need to write EliminatedEvent().Subscribe(....

1 Like

Unfortunately that results in this error:

Depending on how/where you call things and what exact type you need to return you might need to do something like this

Temp:cancelable = Character.EliminatedEvent().Subscribe(KingEliminated)
set KingSubscription = option{Temp}

to satisfy every language requirement.

8 Likes