myself

 

myself is a primitive that is useful when we want an agent to refer to itself while trying to address a different agent or agentset within an ask command or a reporter (e.g., of, with). For example, if we wanted to create a model within which turtles with the same color tried to find each other, we would write the following code:

ask turtles [
    face one-of turtles with [color = [color] of myself]
    forward 1
]

In the model example below, we have a model that is similar to the popular online game agar.io. We have many turtles that represent circles and they move around randomly. When two turtles touch each other, the larger turtle eats the small turtle. We use myself for two purposes: first to compare the two touching turtles within an ask statement in order to pick the larger one, and then to add the sizes of the two touching turtles.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the myself primitive:
 
 
Similar primitives:
nobody

A special value that helps checking if an agent exists or not.

Read more
ask

Asks agents to do things.

Read more
of

Reports the value of an agent-owned variable.

Read more
let

Creates a local variable that only exists within a procedure or a statement surrounded with brackets (`[ ]`).

Read more
 
Learn another primitive: