Passing Which Device in an array signaled an event

I usually add a utils.verse file and include this:

using { /Verse.org/Simulation }
 
(Listenable : listenable(agent)).SubscribeAgent(OutputFunc : tuple(agent, t)->void, ExtraData : t where t:type) : cancelable =
    Wrapper := wrapper_agent(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
    Listenable.Subscribe(Wrapper.InputFunc)
 
wrapper_agent(t : type) := class():
    ExtraData : t;
    OutputFunc : tuple(agent, t) -> void
    InputFunc(Agent : agent):void = OutputFunc(Agent, ExtraData)
 

Then you could do this:

Mut.AgentEntersEvent.SubscribeAgent(PassDevice, index)

PassDevice(Agent:agent, mutzone:int):void=
    block:

The SubscribeAgent allow you to pass an aditional param to the subscribe method

2 Likes