Reputation: 11
I'm trying to make it so that in a while statement it detects whether or not a patch at a certain location is a certain color, this is what I have right now, but it's not working.
while [ patch-at x ytemp with [ pcolor = 44 ] ] [ set ytemp ytemp - 1 ] ask patch-at x ytemp [ set pcolor 44 ]
So basically it runs down the line of patches vertically in this instance, and when it finds that patch that isn't color 44 (dark yellow) and then changes that patch to 44.
Upvotes: 1
Views: 206
Reputation: 4168
The conditional you want in the while
statement is while [ [pcolor] of patch x ytemp = 44 ]
. But you will also have to be sure that you don't get into trouble if all the patches in column x are colored 44. If the world is wrapped, you will (I think) get in an infinite loop. If it is not, you will get an error when you test a patch below the bottom of your world. Perhaps the following might do what you want more safely?
let candidates patches with [pxcor = x and pcolor != 44]
if any? candidates [
ask max-one-of candidates [pycor] [set pcolor 44]
]
It finds all the patches in column x that are not colored 44 and, if there are any, it chooses the one closest to the top of the world to color, which is what your while
loop would have done.
Upvotes: 1