Reputation: 418
How can I build a syntax for an "ifelse" statement that has a turtle in a specified patch and has the turtle determine if the turtle's color is the specified color? The following is sample code, but it won't work. Incidentally, I would like to build it using "max-pxcor - 1".
ifelse count turtles-on patch (max-pxcor - 1) with [color = red] = 1[ ;The following code is omitted
Upvotes: 1
Views: 63
Reputation: 17678
(1) The patch X Y notation selects a specific patch but you have not provided a pycor
. I assume you therefore want any patch with the correct value for pxcor
. How many of those patches are coloured red? (2) If you are not selecting a patch with its identifier, then you are working with a patchset rather than a patch, even if there is only one patch in that set. If you need to get a patch from a patchset, you need one-of
.
If you actually want to identify that patch so you can do something with it, then this approach separates the patches from the turtles so is reasonably readable:
let wanted-patch one-of patches with [pxcor = max-pxcor - 1 and color = red]
ifelse count turtles-on wanted-patch = 1
[
But you could also do:
ifelse any? patches with [pxcor = max-pxcor - 1 and
color = red and
count turtles-here = 1]
[
Of, if you genuinely want the patchset so the total number of turtles on all the right hand column red patches is 1 (so 1 on one patch and 0 on others), then:
ifelse count (turtles-on patches with [pxcor = max-pxcor - 1 and color = red]) = 1
[
For this last one, the () are optional, for readability.
Upvotes: 4