turtles-own

 

turtles-own allows us to define custom turtle characteristics (variables) for all the turtles in a model (in addition to the default turtle characteristics such as color, size, and heading). Although the name of the characteristic will be the same for all the turtles, each turtle will have a different value for these custom characteristics. Once we create such custom characteristics, we can use the set primitive to change its value. For example, if we wanted to create a model of electric vehicles in which each car had a different level of remaining battery, we would write the following code:

turtles-own [remaining-battery passengers]
to setup
    clear-all
    create-turtles 100 [
        set shape "car"
        set remaining-battery random 100
        set passengers one-of [1 2 3]
    ]
    reset-ticks
end
to go
    ask turtles [
        if remaining-battery > 0 [
            forward 1
            set remaining-battery remaining-battery - 1
        ]
    ]
    tick
end

Things to keep in mind when using turtles-own:

In the model example below, we have three cars on three parallel roads. Each car has a different amount of gas in its tank, shown with a label next to each car. When the go button is clicked, each car starts moving forward until they run out of gas.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the turtles-own primitive:
 
 
Similar primitives:
set

Changes the value of a variable (global, local, or agent-owned).

Read more
globals

Defines variables that can be accessed throughout the whole model and has the same value for all the agents.

Read more
patches-own

Defines custom characteristics (variables) for patches. Each custom characteristic can have a different value for each patch.

Read more
with

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

Read more
 
Learn another primitive: