I'd like to subset agents based on values I have in a list. In the code below I have a list of values, called "ActiveID". I'd like to create an agentset of all the turtles who have a turtle-own "ID" values that matches with the numbers in the list "ActiveID". I'd like the turtles with matching values to be not hidden, while all those with "ID" values not in the list to be hidden.
Eventually, each tick the list will change.
The code below doesn't work because I loop through the list "ActiveID" one at a time, resulting in turtles momentarily becoming visible, but then becoming hidden again as the code continues to move through the list. I'd ideally like the turtles with "ID" values that match those in the list to stay not hidden.
globals [ ActiveID ]
turtles-own[ ID]
to setup
ca
create-agents
create-list
reset-ticks
end
to go
Activate
tick
end
to create-agents
create-turtles 20 [
set ID random 10
set size 4
set color red
setxy random-xcor random-ycor
]
end
to create-list
set ActiveID [ 0 4 9]
end
to Activate
foreach ActiveID [ ?1 ->
ask turtles [
ifelse ID = ActiveID [
set hidden? false
] [hide-turtle]]]
end ```