1

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

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
bhc11
  • 157
  • 1
  • 2
  • 14
  • 1
    What's wrong with the code you gave? Does it fail to achieve what you want, or are you looking for different way to code it? You could also pull the conditioning on color out and say `ask turtles with [color = white] [set t 0.99]`, etc. Or you could use lists. e.g. a list of colors and a list of numbers, and then find the index in the color list and use it to index into the number list. – Mars Apr 26 '13 at 06:23
  • I want t to be individual for each turtle. Is there a way to do it? – bhc11 Apr 26 '13 at 09:45
  • 1
    bhc11, I'm still not clear about what the goal is. Does every turtle already have a different color before you set the `t` values? Is the idea that you want to cause every turtle to have a unique color and `t` as soon as the turtle is created? Something like that would not be difficult. If you want to assign `t` a random value, you could use something like `ask turtles [set t random-float 100]`. – Mars Apr 27 '13 at 04:47

1 Answers1

1

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.

Bryan Head
  • 12,360
  • 5
  • 32
  • 50