Context and spaces

22 просмотра
Перейти к первому непрочитанному сообщению

tresnanin...@gmail.com

не прочитано,
12 янв. 2021 г., 00:24:5912.01.2021
– sarl
Dear Mr. Galland, 

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

Thanks

Stéphane Galland

не прочитано,
12 янв. 2021 г., 09:40:2912.01.2021
– 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

не прочитано,
12 янв. 2021 г., 17:28:3512.01.2021
– sarl
Thank you for the information 
Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений