I see a behavior difference between an agentset button (patch, turtle, link) which runs a certain section of code and an observer button which ask
s patches
(or turtles
, or links
) to run the same section of code. Is this a bug in NetLogo? Is this a bug in my code?
Agents are beings that can follow instructions. In NetLogo, there are four types of agents: turtles, patches, links, and the observer. Turtles are agents that move around in the world. The world is two dimensional and is divided up into a grid of patches.
What programming language was NetLogo written in? NetLogo is written mostly in Scala, with some parts in Java. (Scala code compiles to Java byte code and is fully interoperable with Java and other JVM languages.)
The cause of the behavior difference isn't actually a bug, but a rather obscure corner of NetLogo. The ask-concurrent
primitive lies at the core of this behavior. An agentset button uses the same mechanism as ask-concurrent
behind the scenes. Replacing any agentset button with an observer button which uses ask-concurrent
to run the same code on the same agentset shouldn't change the behavior of the button.
Typically the differences between ask
and ask-concurrent
don't amount to much. Turtles may move slightly differently, but it will work basically the same. In some cases though, the differences can be really dramatic. The NetLogo Models Library provides a model called "Ask-Concurrent Example" which explores the differences between ask
and ask-concurrent
.
There is also documentation on this in the NetLogo Programming Guide, in the "Turtle, patch, and link forever buttons" section of http://ccl.northwestern.edu/netlogo/docs/programming.html#buttons; much of the section on ask-concurrent at http://ccl.northwestern.edu/netlogo/docs/programming.html#ask-concurrent also applies.
Note: Use of ask-concurrent
isn't recommended. I'm using it here to clarify the behavior, but it should not be used in general.
Note 2: In general, the safest and most predictable approach is not to use turtle, patch, and link buttons at all. Instead, use observer buttons only, and use ask turtles
, ask patches
, or ask links
in the button code, as appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With