turtles-own [message? other-turtle] to setup ca cct 200 [ set message? false setxy random-float screen-size-x random-float screen-size-y ] set message?-of random-one-of turtles true ; give the message to one of the turtles ask turtles [ color-turtles ; color the turtles red if they have the message, blue otherwise ] end to go every 0.1 [ ask turtles [move] ask turtles [ ;;when they're all done moving, start a new "ask turtles" communicate color-turtles ] ] end ; move randomly to move ;a turtle procedure fd random 4 ; turn a random amount between -40 and 40 degrees, ; keeping the average turn at 0 rt random-float 40 lt random-float 40 end ; the core procedure! to communicate ;;a turtle procedure set other-turtle random-one-of other-turtles-here ; get the ID of another turtle on your patch if(other-turtle != nobody) ; if there is one there [if message?-of other-turtle ; (only IDs of 0 and above are valid) [set message? true] ; if the other turtle has the message ] ; get the message end ; color turtles with message red, and those without message blue to color-turtles ; a turtle procedure ifelse message? [set color red] [set color blue] end @#$#@#$#@ GRAPHICS-WINDOW 295 10 605 341 12 12 12.0 1 13 1 1 1 CC-WINDOW 6 166 289 339 Command Center BUTTON 21 10 76 43 NIL setup NIL 1 T OBSERVER BUTTON 92 10 147 43 NIL go T 1 T OBSERVER BUTTON 21 10 76 43 NIL setup NIL 1 T OBSERVER BUTTON 92 10 147 43 NIL go T 1 T OBSERVER MONITOR 39 67 229 116 NIL count turtles with [color = red] 3 1 @#$#@#$#@ WHAT IS IT? ----------- This code example is a simple demo of turtle-turtle communications. One turtle starts out with a message (the red turtle) and she spreads the message to other turtles. The monitor keeps track of how many turtles have the message by reporting: count turtles with [color = red] Note that if you put a procedure inside an "ask turtles [ ]" bracket, then everything in that procedure will be executed by all of the turtles. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 2.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@