How to get the device when callback is called?

Hey Team,

I am using subscribe to create callbacks on all my devices in the level. One thing I would like to do is know which device the callback is coming from, however it seems verse does not want me to pass additional parameters (such as an int) into the callback of my subscribe.
The only other way I can think of doing this would be to create an individual callback for every single device which would hurt my soul

Code here:

    @editable
    var CaptureDevices : []capture_area_device = array{}

    OnBegin<override>()<suspends>:void=
        for (CaptureDevice : CaptureDevices):
            CaptureDevice.ControlChangeEvent.Subscribe(OnCaptureAreaChangeOwner)

    OnCaptureAreaChangeOwner(InPlayer : agent): void = 
        Print("Capture area taken")
        #Do something depending on which capture device was captured

You can’t, it’s a severe limitation of Verse at the moment. I’m sure somebody is working on it though. What you can do is wrap them up in a custom class and then call out from that class (as we can’t make proper listeners yet either…)

Ah I see, well thank you for the info

Hey, yes it’s not supported yet, as GraemeBB said, you can take a look at handlers Guide to Event Subscribing with Additional Parameters (Handler Functions)

You can either use an handler class like this

# Handler for a button InteractedWithEvent but could be used for any listenable requiring a (agent -> void) signature
on_prop_pickedup_function := type{_(:agent, :int) : void}
pickup_prop_button_handler := class:
    AdditionalData: int
    Callback: on_prop_pickedup_function

    HandleInteractedWithEvent(Agent:agent):void=
        Callback(Agent, AdditionalData)

Or you could use spawn as a quick lightweight solution

for (CaptureDevice : CaptureDevices):
    spawn{WaitForZoneToBeCaptured(CaptureDevice)}

WaitForZoneToBeCaptured(CaptureDevice : capture_area_device)<suspends>:void=
    loop:
        Agent := CaptureDevice.ControlChangeEvent.Await()
        # Agent is the new owner

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