Reputation: 145
I'm looking to get the 'who'/turtle ID of a turtle that occupies the same patch as another, and then add this as an item into a list for both turtles.
For example, say turtle A and turtle B are on the same patch, I'd like to store the who of turtle A in the list for turtle B and the who for turtle B in the list for turtle A.
I realise this may be quite a trivial thing to do, so I attempted to do this with the following code:
if not any? turtles-on neighbors[
if who != who[
set collision-list fput (list (who)) collision-list
]
]
Here, I'm checking the patch to see if it contains another turtle, if it does then I'm trying to store the who (using a condition for if the who is not the same as the current who) and if it isn't, then store this in the collision-list for each agent.
Upvotes: 0
Views: 288
Reputation: 9620
Ordinarily it is a mistake to work with who
numbers instead of the turtles themselves. So I'll illustrate how you might augment a "collision list" of turtles.
turtles-own [clist]
to setup
ca
crt 100 [
setxy random-xcor random-ycor
set clist []
]
ask turtles [adjust-clist]
end
to adjust-clist ;turtle proc
let _ts [self] of (other turtles-here)
set clist (sentence _ts clist)
end
Upvotes: 1