Breed Procedures Example
Model was written in NetLogo 5.0.4
•
Viewed 946 times
•
Downloaded 130 times
•
Run 2 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This shows how to use the run
command to give different breeds different definitions of the "same" procedure.
THINGS TO NOTICE
You could accomplish the same thing with code like this:
ifelse breed = dogs
[ dogs-speak ]
[ ifelse breed = cats
[ cats-speak ]
[ cows-speak ] ]
but such code is tedious to write and runs slower.
NETLOGO FEATURES
The run
command is fast when you use it over and over again on the same strings, so using this technique won't hurt the performance of your model.
Comments and Questions
Click to Run Model
breed [dogs dog] breed [cats cat] breed [cows cow] to setup clear-all set-default-shape dogs "dog" set-default-shape cats "cat" set-default-shape cows "cow" ask patch 0 1 [ sprout-dogs 1 ] ask patch 0 0 [ sprout-cats 1 ] ask patch 0 -1 [ sprout-cows 1 ] end to go ;; "turtles" refers to all of the turtles, ;; no matter what breed they are ask turtles [ ;; each turtle takes its breed, adds "-speak" ;; onto it, and then runs that procedure run word breed "-speak" ] end ;; Here we have the separate procedure definitions ;; for each breed. to dogs-speak ;; dog procedure set label "arf arf!" end to cats-speak ;; cat procedure set label "meow!" end to cows-speak ;; cow procedure set label "mooooo!" end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Breed Procedures Example.png | preview | Preview for 'Breed Procedures Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.