Context and spaces

22 views
Skip to first unread message

tresnanin...@gmail.com

unread,
Jan 12, 2021, 12:24:59 AM1/12/21
to sarl
Dear Mr. Galland, 

When an agent spawn multi agents, how to emits an event to several (certain) agents?

Thanks

Stéphane Galland

unread,
Jan 12, 2021, 9:40:29 AM1/12/21
to sarl
Hello.

Basically, the agents have access to an "emit" functions that is providing by the DefaultContextInteractions or the ExternalContextAccess capacities.

The prototype of the function is:

def emit(e : Event, scope : (Address)=>boolean)

The first parameter is the event to be emitted. The second parameter is named the "scope". It is a lambda expression that evaluates if an agent should receive the event.

For example:

emit(new MyEvent) [ it.UUID == myAgentID]

This line emits an occurrence of MyEvent. The code between the brackets is the lambda expression (written as its externalized form) that is evaluated for each agent. The parameter of this lambda (named "it") is the address of the agent to test. "myAgentID" is a local variable that contains the UUID of the agent that is supposed to receive the event. Then the lambda expression tests if the UUID of the potential receiving agent ("it.UUID") is equal to the expected UUID of the receiving agent (myAgentID).

Since the scope is written as a lambda expression, you could write a more complex expression, based on boolean operators for example.

You could find a small tutorial on a "ping-pong event exchange" that may provide to you inputs related to scoped event emitting: http://www.sarl.io/docs/official/tutorials/PingPong.html. You could take a look in section 3.3 and 3.4.

All the best.

tresnanin...@gmail.com

unread,
Jan 12, 2021, 5:28:35 PM1/12/21
to sarl
Thank you for the information 
Reply all
Reply to author
Forward
0 new messages