5

I see a behavior difference between an agentset button (patch, turtle, link) which runs a certain section of code and an observer button which asks 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?

Robert Grider
  • 261
  • 1
  • 7

1 Answers1

5

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.

Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
Robert Grider
  • 261
  • 1
  • 7