Skip to main content

4.6) Working With Variables (SET vs. LET)


Netlogo differentiates two type of variables; global and local variables. Global variables are known to all procedures, local variables are known only to the one procedure you are creating the variable in.

Use let to create and set the value of a new local variable. Use set to change the value of the just created or any other existing (global) variable.

let mean-neighbor-size mean [size] of turtles-on neighbors
set mean-neighbor-size mean-neighbor-size ^ 0.5

How does one patch (turtle) give its value of a variable to other patches? There are two ways to do this:

  1. I can ask all my neighbours to set their pcolor (build-in patch colour variable) to my colour
  2. ask neighbors [set pcolor [pcolor] of myself]
    
  3. I can create a local variable called my-color and then set all neighbors pcolor according to the value of my-color
  4. let my-color pcolor
    ask neighbors [set pcolor mycolor]