Reputation: 418
How can I ask one of the turtles in multiple patches? I want to select one of the turtles in the specified patches. (or I want to ask one turtle in a specified range of cells) For example, I want to use the following syntax: But it doesn’t work.
ask turtles-on patch (1, 0) or (2, 0) or (3, 0)
move-to patch max-pxcor 1
or
ask turtles with [(50 0) < max-pxcor]
move-to patch max-pxcor 1
Upvotes: 0
Views: 544
Reputation: 17678
Your first problem is the way you are identifying patches. For example, the correct form of "patch (0, 1)" is patch 0 1
- no brackets and no comma. You used this syntax correctly in the move-to
bit of your code.
To make the first version work, you need to create a patch set of the patches and then select from that:
ask turtles-on (patch-set patch 1 0 patch 2 0 patch 3 0)
[ move-to patch max-pxcor 1
]
I'm not really sure what your logic is intended to be on the second version since you are comparing (sort of) a number to another number. Even if you had the syntax correct, it would be either true for all turtles or false for all turtles. Based on your first example, I suspect you want the turtles to look at their own patch and, if pxcor is < 50 and the pycor is 0, you want them to move. That would be:
ask turtles with [pxcor < 50 and pycor = 0]
[ move-to patch max-pxcor 1
]
If you want the turtles with all the patches in the row (not just the ones up to 50), then you can do:
ask turtles with [pycor = 0]
[ move-to patch max-pxcor 1
]
Note that the second and third examples use the fact that a turtle has automatic access to the variables owned by the patch where it is located.
Note that if you only want one of the turtles (as you say in your text but not in the example code) then you need ask one-of turtles
instead of ask turtles
.
Upvotes: 3