bhc11
bhc11

Reputation: 169

Ask all turtles but apply to every turtle differently - NetLogo

I'm using net logo and I want to ask all turtles something but apply it to every turtle individually:

to setup-t 
    ask turtles [
      if color = white [ set t 99 ]
      if color = red [ set t 92.4 ]
      if color = orange [ set t 85.8 ]
      if color = brown [ set t 79.2 ]
      if color = yellow [ set t 72.6 ]
      if color = green [ set t 66 ]
      if color = lime [ set t 59.4 ]
      if color = turquoise [ set t 52.8 ]
      if color = cyan [ set t 46.2 ]
      if color = sky [ set t 39.6 ]
      if color = blue [ set t 33 ]
      if color = violet [ set t 26.4 ]
      if color = magenta [ set t 19.8 ]
      if color = pink [ set t 13.2 ]
      if color = black [ set t 6.6 ] 
    ]
end

In this way it applies to all turtles, but every turtle has a different color and I want t to apply to every turtle differently and individually. How can I do that? Thanks

Upvotes: 1

Views: 777

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

To make a variable that can be different for every turtle, declare it with turtles-own. So in your case, you would put

turtles-own [ t ]

Then, the code you have should work.

Upvotes: 1

Related Questions