Reputation: 129
I need some help. I have some turtles linked by links. Turtles have both a variable "x" and a variable "y". The latter can be true or false. I would like to do the following: each turtle has to "inspect" the "y" variable of all the neighbors linked to it, one at a time. Then if "y" is true the (inspecting) turtle updates its "x" = x + 1, if "y" is false the (inspecting) turtle updates its "x" = x - 1. Summaring, each turtles updates it "x" during each meeting. Thererore if a turtle has 3 links with "y" true, it "x" has to be x + 3. Thanks
Upvotes: 0
Views: 572
Reputation: 17678
So the value of X is given by the number of linked turtles with true y - number of linked turtles with false y? If so, you want something like:
ask turtles
[ set X count link-neighbors with [Y?] - count link-neighbors with [not Y?] ]
Note that standard practice in NetLogo is to have a question mark at the end of the variable name for boolean variables and I have named the y variable accordingly.
Upvotes: 2