member?

 

member? can be used with lists or agentsets, but is more commonly used with lists. member? reports true if the given value or agent appears in the given list or agentset. For example, member? 3 [12 -5 3 6 1] would report true, while member? 5 [12 -5 3 6 1] would report false.

In the model example below, we have a building that represents a library and some turtles who represent patrons. While the turtles move around randomly, our library checks at each tick if there is any patron nearby. If there is a patron, our library checks if the patron is a member of the library. If the patron is a member, our library asks them to change their shape to indicate that this patron either picked or dropped a book.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the member? primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the member? primitive:
 
 
Similar primitives:
count

Counts the number of agents in an agentset.

Read more
if

Carries out a provided set of rules (code) if a given condition is true. Does nothing if a given condition is false.

Read more
n-of

Reports "n" randomly picked agents from an agentset or items from a list.

Read more
with

Reports a subset of the original agentset that only contains the agents with specified characteristics.

Read more
 
Learn another primitive: