On this page
Quick reference, glossary, and NetLogo bridge
Manual contents | Project settings | NLSimMain reference | NLPatch reference | NLTurtle reference | NLRoot reference | Supporting types | Troubleshooting | Alphabetical API index | Compatibility
This is a model-author map; use the alphabetical index for
method/property lookup.
Examples assume lifecycle: "aligned" and appropriate Project configuration.
Start here: where does this line belong?
| Task | Home |
|---|---|
| Declare palettes, inputs, displays, geometry, visit order | Project |
| Save the Patch/Turtle classes supplied by the runtime | Main constructor |
| Create patches / initial turtles | Main initCells() / initAgents() |
| Register a custom Store or public updater once | Owner's init() |
| Activate static patch rules; rebuild population-dependent references | setup() |
| Make a shared decision before individual rules | Main coordinate() |
| Apply one environmental rule | Patch patchStep() |
| Sense, eat, turn, or move one turtle | Turtle turtleStep() |
| Count/report the completed tick | Main update() |
| Restore custom state without reallocating it | Owner's reset() |
Keep required base calls. In particular, preserve super.init() when
overriding Main init, super.reset() in reset overrides, and
super.turtleStep() for movement/updaters. Preserve super.patchStep() for
built-in patch updaters and super.turtleShift() for newborn bookkeeping.
The four lifecycle jobs
| Hook | Put here | Do not put here |
|---|---|---|
constructor |
Stable fields/Stores; wiring required by early setters | Manual init/setup calls; queries of populations not yet built |
init |
One-time registration after context/defaults; Main calls super.init | Repeated reset work; Main population-dependent calculations |
setup |
Relationships/activation/derived output after populations exist; safe to repeat | Listener accumulation; rebuilding a surviving Store |
reset |
Owner's local state restoration; preserve base behavior | Child/world reconstruction or manual init/setup |
Whole-world reset is resetWorld(). Patches/Main survive; turtles are replaced.
See lifecycle.
One ordinary tick
Main coordinate
-> selected patch/turtle step rules (Project visit order)
-> shift: commit proposals and process population changes
-> advance clock
-> Main update
For dt: 1, the first coordinate sees time 0 and the first update sees time 1.
Use this.currentTime in Main, or this.main.currentTime in a patch/turtle.
Birth/death insertion and local visibility have distinct boundaries; see
population timing.
visitMode |
Individual rules |
|---|---|
"C" |
Selected patches |
"A" |
Turtles |
"C_A" |
Selected patches, then turtles; no commitment between them |
"A_C" |
Turtles, then selected patches; no commitment between them |
"C/A", "A/C" |
Advanced: an intermediate shift separates the groups |
"No" |
No automatic individual steps |
Patch selection is separate from visit order. For an always-active patch,
call this.main.visitAlways(this) in patch setup. For sparse activation use
touchPatch / addToNextSites with an explicit reactivation policy.
Do not also transiently activate an always-active patch unless duplicate
visits are intended. visitAll = true is not a once-per-tick guarantee.
See Main visitation and
Programming patches.
Read, set, or propose?
| Intention | Built-in example | Custom Store |
|---|---|---|
| Read committed state | patch.color |
food.get() |
| Initialize and replace reset baseline | patch.color = 1 |
food.initialize(1) |
| Immediate current/next edit, baseline retained | patch.currentColor = 1 |
food.set(1) |
| Propose for commitment | patch.nextColor = 1 |
food.next = 1 |
| Install built-in rule once | patch.colorUpdater = () => 1 |
food.setUpdater(() => 1) |
| Evaluate repeating rule | aligned base patch/turtle step | explicitly food.autoNext() |
| Restore baseline | owner's reset / built-in base reset | explicitly food.reinitialize() |
Register a custom Store with main.synchronize(food) for commitment.
Activation, reporting, reset, and updater evaluation are separate responsibilities.
See state management.
Local-query choices
| Need | Operation |
|---|---|
| Nearest patches | patch.neighbors() |
| Grid-distance shell | patch.ring(distance) |
| Filled grid neighborhood with center | patch.block(distance) |
| Filled grid neighborhood without center | patch.blockX(distance) |
| Square-only orthogonal neighbors | main.nhood4(patch) |
| Other turtles on selected patches | turtle.nhoodPatches(patches) |
| Count matching other turtles | turtle.nhoodCount(predicate, patches) |
| Euclidean disk | main.patchesInRadius(patch, radius) |
| Turtles by actual distance from coordinate point | main.turtlesInRadius(patch, radius) |
Grid distances: nonnegative safe integers. Radii: finite nonnegative numbers. Selections deduplicate; wrap can shrink their sizes. Ring/blockX exclude self even after wrapping. See neighborhoods for all return types, zero-distance cases, hex coordinates, boundaries, and side effects.
Angles and motion
| Heading | Direction |
|---|---|
0 |
East |
Math.PI / 2 |
South |
Math.PI or -Math.PI |
West |
-Math.PI / 2 |
North |
theta uses radians; right(degrees) and left(degrees) return radians.
Assign the result to nextTheta; calling either alone does not turn.
Trajectory base movement uses pending speed/heading before its built-in
updaters. moveNext(x, y) proposes a destination; it is not a teleport before
the current rule finishes.
See turtles.
| Intention in Turtle | Public operation |
|---|---|
| Initialize position and its companion representation | this.initLocation(x, y) |
| Edit position immediately | this.moveTo(x, y) |
| Propose a destination | this.moveNext(x, y) |
| Set speed for this trajectory move | Assign nextSpeed before super.turtleStep() |
| Turn for this trajectory move | Assign nextTheta before the base step; avoid a competing heading updater |
| Turn for the following move | Propose heading after movement is scheduled |
| Find current occupied patch | this.myPatch() |
| Sample current / pending heading | this.patch_ahead(d) / this.patch_ahead_next(d) |
| Hide without removing | this.setVisible(false) |
| Request removal and stop this rule | this.die(); return; |
Check sampled patches for null at Edge boundaries. Sensing a destination is
not checking a whole path for collisions. x and y are read accessors;
do not assign them to move. Cell lookup boundary and agent edge physics are
separate settings. Avoid the legacy fd/forward shortcuts; see
helper caveats.
Inputs, outputs, and run controls
These fragments are Main operations unless another owner is shown:
| Need | Operation / reminder |
|---|---|
| Read numeric input | this.getParam("SPD") |
| Read a 0/1 toggle | this.getBParam("GROW") |
| Named input read for turtles | Main getter get SPD() { return this.getParam("SPD"); }; Turtle reads this.main.SPD |
| One chart value | this.show("TOTAL", total) |
| Several chart series | this.show("STATES", countA, countB) |
| Already have a series array | this.showList("STATES", counts) |
| Append configured logger output | this.log("EVENTS", "message") |
| Clear configured logger | this.clearLogger("EVENTS") |
| Request a run stop | this.halt() |
| Stop on a condition at status publication | Set this.stopWhenTrue = () => this.currentTime >= 100 once in init |
| Reset the whole world programmatically | this.resetWorld() |
Input/output codes are case-sensitive and must match Project. A getter is a live read, not a saved copy. Declaring a slider does not make every property with a similar name follow it. Initial population count is not live resizing.
Publish initial outputs in setup and committed outputs in update.
The number/order of chart values must match the legend. Do not pass an array
as one show argument when you mean multiple series; use showList.
Do not call statusToJson() for inspection: it consumes pending reporting.
Neither halt nor speed zero resets state; speed zero also does not stop time.
Do not create a second timer or manually advance the clock inside a rule.
Choose a small check
| Concern | Worked check |
|---|---|
| Patch state transitions | Fire milestones |
| Synchronous fields, color timing, and conservation | Heat spreading |
| Movement, units, wrapping | One Walkers turtle |
| Counts and resettable Main memory | Population peak |
| Sensing and turn timing | Obstacle route |
| Food claims and custom Store reset | Stationary Grazer |
| Movement and resource budgets | Alternating grazing |
| Unexpected result | Troubleshooting workflow |
NetLogo concepts: useful analogies, not literal translations
| Familiar idea | NL API approach | Important difference |
|---|---|---|
| Observer | Main | A JavaScript object with lifecycle hooks, not an implicit global context |
| Patches / turtles | Patch / Turtle subclasses | Model rule methods receive context through this and this.main |
globals |
Main fields or Stores | Ordinary fields are immediate; Stores can stage updates |
patches-own, turtles-own |
Fields/Stores allocated on each instance | Allocation and reset ownership are explicit |
setup button |
Runtime startup / world Reset and coordinated setup | Do not translate every NetLogo setup command into constructor calls |
go |
Runtime loop with coordinate, local steps, shift, update | Do not add a competing timer |
tick, ticks |
Clock managed by runtime; currentTime reads it |
A model's ordinary rule does not manually advance time |
ask turtles [...] |
Turtle step or explicit turtleVisit |
Automatic traversal is not a promise of randomized NetLogo ask order |
set color red |
Palette number via public color properties | Palette entry/index rather than a NetLogo color constant; choose current vs next |
set heading ... |
theta, currentTheta, nextTheta |
Radians, zero east, clockwise with screen y |
rt 15 |
this.nextTheta = this.right(15) |
Helper returns an angle; assignment is required |
fd speed |
Trajectory base step using pending speed | Do not directly substitute legacy forward/fd helpers |
patch-here |
this.myPatch() |
Returns current occupied patch; hex coordinates need the occupancy conversion |
neighbors, neighbors4 |
neighbors(), square-only Main nhood4 |
Sets/arrays and center/edge rules are documented explicitly |
other turtles in-radius r |
Radius query plus explicit self filter | Query center and distance geometry must match your intended rule |
hatch, sprout |
Main parent/patch birth helpers | Insertion/setup deferred; custom fields not automatically copied |
die |
this.die(); return; |
Queue/removal and immediate rule control are separate |
| Sliders | Project inputs, getParam(code) |
Declare how/when the model uses them |
plot |
Main show/showList to a configured display | Output code and series shape must match configuration |
one-of / n-of |
NLRoot one_of / n_of on arrays | Explicit array contract; empty one_of is undefined |
See tools and utilities for Enum, Property, random draws, sampling, summaries, strings, and supporting classes.
Glossary
- Aligned lifecycle: explicit opt-in initialization/reset ordering used by this guide. Legacy apps without the flag keep old behavior.
- Activation: selecting patches whose step rules will execute; independent of whether they are visible or have a pending Store update.
- Baseline: the initial value/factory retained for Store reinitialization.
- Commit / shift: adopting proposed next values as current values.
- Coordinate: Main's pre-step hook for shared decisions, not a location.
- Current: committed state normally read by synchronous rules.
- Grid distance: integer square/hex neighborhood layers, not a Euclidean radius and not display pixels.
- Next / pending: a proposal awaiting commitment; sharing it as a claim ledger creates deliberate order dependence.
- Newborn: queued/inserted turtle with a delayed local-visibility boundary.
- Palette: Project's mapping of numeric color values to rendered colors; cell and agent palettes are independent.
- Radius: Euclidean distance under the documented coordinate metric and shortest-wrap rules.
- Registration: wiring a Store, listener, or updater for a responsibility; assigning an updater is not the same as evaluating it.
- Setup: a runtime-invoked, repeatable population-ready hook, not a synonym for construction or world reset.
- Store: current/next/baseline state plus optional updater/listeners.
- Synchronous rule: reads committed state and proposes state for a later shared boundary; ordinary JavaScript assignment is not made synchronous.
- Tick: one runtime iteration; its phase boundaries depend on visit mode.
- Topology: square/cartesian or hexagonal geometry and coordinate convention.
- Visit mode: configured ordering of patch/turtle work and intermediate shifts.
- Wrap: opposite edges are identified; do not assume grid-query normalization applies to every unrelated legacy movement helper.