Variables (For a Printable Version Click Here) State Variables State variables are built in characteristics of turtles and patches.
Turtles have 7 state variables:
Patches have 3 state variables: The observer has no state variables.
You can have access to a state variable by using its name in an expression. For example:
All state variables, with the exception of the xcor
and ycor of a patch, can be changed using
the set command. For example:
Note that the set command performs the same function whether it is separated by a space from the variable or not. Creating New 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] 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. Variable Suffixes
You can access or set the state variable of another turtle or patch by using
-at, -to
, or -towards suffixes. For example:
-of takes a turtle ID number as its argument. Local Variables Like
For example: 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. You can pass more than one parameter to a procedure by separating the variable names with a space. For example: Here are a list of commands that affect variables: |
|||||||||||
|