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:
- I can ask all my neighbours to set their pcolor (build-in patch colour variable) to my colour
- I can create a local variable called my-color and then set all neighbors pcolor according to the value of my-color
ask neighbors [set pcolor [pcolor] of myself]
let my-color pcolor ask neighbors [set pcolor mycolor]