Diesel
Diesel

Reputation: 519

Setting turtle coordinates to patch color in netlogo

I'm working through creating my first Netlogo model and I'm trying to create a turtle only on patches that have a certain color

 create-h2o (totalmoles * h20number / 100)[
    set shape "circle"
    set color black
    set size 0.2
    setxy one-of patches with [pcolor = liquid]
  ]

which doesn't work as setxy needs an X and a Y coordinate

I've also tried creating the turtles at randomxy coordinates and then moving them to patches

setxy random xcor random ycor
move-to one-of patches with [pcolor = liquid]

right after, but I get an error that "MOVE-TO expected input to be an agent but got NOBODY instead"

Any help?

Upvotes: 1

Views: 829

Answers (1)

JenB
JenB

Reputation: 17678

The reason the second doesn't work is because there is no such colour as 'liquid' so patches with [pcolor = liquid] is empty. But the approach is fine. Simply replace that with a real color and it will work.

You might also want to look up sprout to create your turtles. In this case it's probably better to stick with your approach because it looks like you will be having some random number of h20 turtles on the water patches.

Upvotes: 1

Related Questions