Reputation: 1
I am trying to create a code that will allow me to get the who numbers of 10 turtles and store them in a list. However, the "who" number can only be added to the list if it has not been added to the list before.
I have to use the "foreach" command to check if the number has already been added to the list.
Any suggestions on how to do so?
My code:
turtles-own [contact-list]
to setup
clear-all
create-turtles 10 [
set contact-list []
print who
]
reset-ticks
end
to go
ask turtles [
set contact-list lput [who] of one-of other turtles-here contact-list
foreach contact-list[
; this is where the command goes
]
print contact-list
]
end
Upvotes: 0
Views: 164
Reputation: 4168
Might it be easier to add all the who numbers to the list and then use the remove-duplicates
primitive to remove the duplicate numbers? I assume that you have a reason for putting who numbers into the list rather than having a list of the agents themselves, or an agentset. In general, who numbers are to be avoided.
Upvotes: 1