1

A quick question:

How to set every turtles different colors?

Like, I'd to set the random color whose value ends in *6 or *3 to turtles.

My code:

ask  turtles [set color ((random 14) * 10 + 6 ) or ((random 14) * 10 + 3 ))]

But it doesn't work. Since the or here is wrong.

Is there any other methods express or here?

I appreciate any kinds of help! Thank you!

Giorgio
  • 13
  • 2

1 Answers1

2

or is a logical test. What you want is to assign one-of those values. I think this is what you want:

ask  turtles
[ set color one-of (list ((random 14) * 10 + 6 ) ((random 14) * 10 + 3 )) ) 
]
JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thank you JenB! Yes I think `one-of` appears to make sense. But `random` in your code triggers an "expected literal value" warning. Also, I think `one-of` requires a list as input, but `random X` is a number. I revised a bit as `ask turtles[set color one-of [list((random 14) * 10 + 6 ) ((random 14) * 10 + 3 )) ] ], but it doesn't work either. Maybe do you have any ideas how to change it? Thanks! – Giorgio May 30 '21 at 15:48
  • try the revision - i made the list explicit rather than rely on the [ ] syntax – JenB May 31 '21 at 07:56