Paul
Paul

Reputation: 189

Ask for the value of a variable of all turltes in Netlogo

Hello i have the next code to give a value to the variable "payoff" of the population of turtles with 3 different colors

turtles-own
  [
   payoff
   ]

to pay
let nearby other turtles in-radius 1
 ask turtles with [color = blue] 
  [
  if any? nearby with [color = red]
  [
 set payoff -1 
  ]
  ]
end   

So what i want to do is check the payoff of the turtles with color blue and if the payoff is less than 0 (i.e -1) they change their color to red, but i need to do this for each individual blue turtle so what code can i use? I try using "one-of" and "any?" but i think that this code its not for the purpose that i want. Any suggestions?

Upvotes: 1

Views: 38

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

ask turtles with [ color = blue ] [
  if payoff < 0 [
    set color red
  ]
]

Alternatively:

ask turtles with [ color = blue and payoff < 0 ] [ set color red ]

Upvotes: 2

Related Questions