Variables

(For a Printable Version Click Here)

A note on using variables:

You can create new state variables for turtles, patches, and the observer. Whenever you create a new variable, StarLogo automatically creates a collection of new procedures to facilitate the use of the variable. For example, if you create the variable age for the turtles, then the turtles can use the procedure setage to change the value of the variable, and they can use the procedure age to access the value of the variable.

You create new variables with the commands turtles-own, patches-own, and globals. You can type these commands in either the turtle procedures window or the observer procedures window (but not both), like this:

turtles-own [age speed] Creates turtle variables age and speed
patches-own [food] Creates patch variable food
globals [time] Creates global variable time

For turtle variables, the example age is used.  For patch variables, the example food is used.  And, for global variables, the example time is used.  In order to use the commands listed below, you must first create the variables you want.

Here are a list of commands that affect variables. A popup box will open up if you click on the command name.

A
age

age-at

age-of

age-towards

B
C
D
E
F
food

food-at

food-towards

G
H

I

 

 

 

 

J
K
L

let

M
N
O
P
Q
R

 

S

set

setage

setage-at

setage-of

setage-towards

setfood

setfood-at

setfood-towards

settime

T
time
U
V
W
X
Y
Z

Local Variables

Like globals, local variables are not associated with any specific patch or turtle. However, the exist only within the procedure within which they are declared.

Example:
to check
let [:num who + color]
if :num > who * 2 [setc red]
end

Parameters

Parameters are like local variables, in that they only exist during the procedure they are associated with. They are "declared" when the caller of procedure gives them a value.

Example:
to move :number
fd :number
lt random 360
bk :number
rt random 360
end

to go
move 30
end