How to get the reference of a Volume in an array based on Signal event

Hey, I think this should work for you:

# Create a class which holds references to required values defined when subscribing
volume_test_device_zone_enter_handler := class():

    Volume: volume_device

    On(Agent: agent): void =

        Location: vector3 = Volume.GetTransform().Translation
        Print("This is the location of the Volume: {Location}")


volume_test_device := class(creative_device):
    @editable
    VolumesArray :[]volume_device = array{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>: void =

        # This is a Verse for loop sytax
        for. I -> Volume : VolumesArray
        do. Volume.AgentEntersEvent.Subscribe(volume_test_device_zone_enter_handler{Volume:=Volume}.On)

Once you understand how that’s working, you may want to look at Wrapping Subscribe() to pass additional data to listeners | Uefn Code Snippet. That handles this in a more generic way but will probably be confusing to get straight into if you are new to coding or Verse.

1 Like