-
Notifications
You must be signed in to change notification settings - Fork 1
03. Tutorial 3
In this tutorial, we will learn how to set activation priority to nodes.
The playful code:
program:
display, while time_modulo_5, priority of 2 | value="A"
display, priority of 1 | value="B"
In this program, 2 instances of "display" are competing for access to the "console" resource. When you visited tutorial 1, you saw that the python code for the display node requests access to the "console" resource to run:
if self.ask_for_resource("console"):
playful.console(str(id(self)),"\n"+str(self.value)+"\n")
Only one instance of playful node can be granted a resource at the same time, i.e. only one instance of "display" can run at the same time).
The priority keyword is used to decide which instance should get the resource when both instances ask for it, which happens when time_module_5 return True. Priority of 2 being higher than 1, the first instance (printing 'A') wins.
(when time_modulo_5 returns False, the first instance is not activated, and therefore does not ask for the resource, which is attributed to the second instance, which prints 'B')
You may play with the priorities values and observe changes. Note that if you set a negative priority, the related leaf node never activates
Playful has been developed at the Max Planck Institute for Intelligent Systems, Tuebingen, Germany