Skip to article frontmatterSkip to article content

Let’s learn the basic building blocks that all programming uses.

Variables: Things That Can Change

Variables store information that can change over time.

Examples in real life:

Examples in NetLogo:

Think of Variables as Labels

Imagine each turtle wearing name tags:

Commands: Actions Agents Can Take

Commands tell agents what to do.

Basic movement commands

Property change commands

Social commands:

Reporters: Questions Agents Can Answer

Reporters ask questions and get answers.

About myself:

About others:

About the environment:

Procedures: Grouping Instructions Together

Procedures are like recipes - they group related instructions.

to move-randomly
  right random 360    ; turn a random amount
  forward 1           ; move forward 1 step  
end

Simple Procedure Example

This procedure called move-randomly does two things:

  1. Turn a random direction (0-360 degrees)
  2. Move forward 1 step

Now you can just say move-randomly instead of repeating those two lines!

Why use procedures?