Ask-Concurrent Example
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This example demonstrates the difference between the ask
and ask-concurrent
commands.
HOW TO USE IT
Press SETUP to make some turtles.
Then press either of the two buttons that ask the turtles to go forward 5 steps. (Don't leave them both pressed at once.)
At the normal speed, the turtles may move so fast you won't see how the buttons are different. If needed, use the speed slider to slow down the model until you can watch the turtles move one at a time.
The GO button uses ask-concurrent
in a slightly more elaborate way. It shows turtles acting currently even though each turtle is running a while
loop, not just a simple fd
command.
THINGS TO NOTICE
How do the turtles move with ask turtles [ fd 5 ]
?
How do they move with ask-concurrent
instead of ask
?
For details on ask-concurrent
, read the Ask-Concurrent section of the Programming Guide in the NetLogo User Manual.
NETLOGO FEATURES
The view update mode is set to "continuous" so you can see the agents move one at a time by moving the slider towards "slower".
Comments and Questions
turtles-own [done?] ;; this is used only by GO-TURTLES-ALTERNATE to setup clear-all ask patches with [pycor = 0] [ sprout 1 [ set heading 0 ] ] reset-ticks end to go ;; make a red patch in each column ask patches with [pycor = 0] [ ask patch-at 0 (random world-height) [ set pcolor red ] ] ;; have every turtle move forward until it ;; finds the red patch in its column go-turtles tick end to go-turtles ask-concurrent turtles [ while [pcolor != red] [ fd 1 ] set pcolor black ] end ;; Here's one way to do the same thing as GO-TURTLES but using ;; ASK instead of ASK-CONCURRENT. The behavior of the turtles ;; is the same and the visual result (turtles working on their ;; task concurrently, rather than each completing its task ;; serially) is the same. Note the use of a turtles-own variable. to go-turtles-alternate ask turtles [ set done? false ] loop [ let still-moving turtles with [not done?] if not any? still-moving [ stop ] ask still-moving [ ifelse pcolor = red [ set pcolor black set done? true ] [ fd 1 ] ] ] 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 | |
---|---|---|---|---|
Ask-Concurrent Example.png | preview | Preview for 'Ask-Concurrent Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.