FAQ (Frequently Asked Questions)

NetLogo 4.0.5 User Manual   

Feedback from users is very valuable to us in designing and improving NetLogo. We'd like to hear from you. Please send comments, suggestions, and questions to feedback@ccl.northwestern.edu, and bug reports to bugs@ccl.northwestern.edu.

Questions

General

Downloading

Applets

Running

Usage

Programming

BehaviorSpace

Extensions

General

Why is it called NetLogo?

The "Logo" part is because NetLogo is a dialect of the Logo language.

"Net" is meant to evoke the decentralized, interconnected nature of the phenomena you can model with NetLogo, including network phenomena. It also refers to HubNet, the multiuser participatory simulation environment included in NetLogo.

How do I cite NetLogo in an academic publication?

NetLogo itself: Wilensky, U. 1999. NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.

HubNet: Wilensky, U. & Stroup, W., 1999. HubNet. http://ccl.northwestern.edu/netlogo/hubnet.html. Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.

How do I cite a model from the Models Library in a publication?

The correct citation is included in the CREDITS AND REFERENCES section of every model's Information tab.

Where and when was NetLogo created?

NetLogo was first created in 1999 by Uri Wilensky at the Center for Connected Learning and Computer-Based Modeling, then at Tufts University in the Boston area. NetLogo grew out of StarLogoT, which was authored by Wilensky in 1997. In 2000, the CCL moved to Northwestern University, in the Chicago area. NetLogo 1.0 came out in 2002, 2.0 in 2003, 3.0 in 2005, and 4.0 in 2007.

What programming language was NetLogo written in?

NetLogo is written entirely in Java (version 1.4.1).

What's the difference between StarLogo, MacStarLogo, StarLogoT, and NetLogo?

The original StarLogo was developed at the MIT Media Lab in 1989-1990 and ran on a massively parallel supercomputer called the Connection Machine. A few years later (1994), a simulated parallel version was developed for the Macintosh computer. That version eventually became MacStarLogo. StarLogoT (1997), developed at the Center for Connected Learning and Computer-Based Modeling (CCL), is essentially an extended version of MacStarLogo with many additional features and capabilities.

Since then two multi-platform Java-based multi-agent Logos have been developed: NetLogo (from the CCL) and a Java-based version of StarLogo (from MIT).

The NetLogo language and environment differ in many respects from MIT StarLogo's. Both languages were inspired by the original StarLogo, but were redesigned in different ways. NetLogo's design was driven by the need to revise and expand the language so it is easier to use and more powerful, and by the need to support the HubNet architecture. NetLogo incorporates almost all of the extended functionality of our earlier StarLogoT, as well as a great many newer features.

What license is NetLogo released under? Are there are any legal restrictions on use, redistribution, etc.?

The license is given in the "Copyright" section of the NetLogo User Manual, as well as in the application's about box and the README file accompanying the download.

A quick summary of the license is that use is unrestricted, including commercial use, but there are some restrictions on redistribution and/or modification (unless you contact Uri Wilensky to arrange different terms).

We are in the process of reevaluating the language of the license in response to user feedback. In the future, we intend to send out a revised license.

Is the source code to NetLogo available?

At present, no. We are working on eventually releasing the source under an open source license.

In the meantime, though, NetLogo is not a closed platform. We provide an API for controlling NetLogo from external Java code and an API for users to write new commands and reporters in Java. (See "Controlling" and "Extensions" in the User Manual.) We encourage users to write NetLogo extensions and share them with the NetLogo user community.

Do you offer any workshops or other training opportunities for NetLogo?

We offer workshops from time to time. If a workshop has been scheduled, we will announce it on the NetLogo home page and on the netlogo-users group. If interested in this type of opportunity, please contact us at feedback@ccl.northwestern.edu.

Are there any NetLogo textbooks?

We at the CCL have hoped to write several NetLogo textbooks for quite some time. These could be aimed at different audiences, such as: middle school, high school, undergraduate course in modeling or complexity, practical guide for interested adults.

Unfortunately, we have not yet been able to find the time to make these happen. If anyone from the user community would like to collaborate on such a venture, please let us know. We would welcome it.

Is NetLogo available in a Spanish version, German version, (your language here) version, etc.?

At present, NetLogo is available only in English.

We plan to eventually make it possible for users to produce their own foreign-language "packs" for NetLogo and share them with each other. In order to do this, we need to separate all of the English text from the rest of the source code, so that is separately editable. We're not sure when this will happen.

Is NetLogo compiled or interpreted?

Short answer: partially compiled; we are working towards a full compiler.

Long answer: NetLogo does include a compiler that generates Java byte code. However, this compiler does not yet support the entire language, so some parts of user code are interpreted. We are working on expanding the compiler to support the entire language. Note that our compiler generates Java byte code, and Java virtual machines have "just-in-time" compilers that in turn compile Java byte code all the way to native code, so user code is ultimately translated to native code.

Has anyone built a model of <x>?

The best place to ask this question is on the NetLogo Users Group.

You should also check the Community Models section of our Models Library web page.

Are NetLogo models runs scientifically reproducible?

Yes. NetLogo's agent scheduling algorithms are deterministic, and NetLogo always uses Java's "strict math" library, which gives bit-for-bit identical results regardless of platform. But keep the following cautions in mind:

Will NetLogo and NetLogo 3D remain separate?

No. The split is temporary. Eventually a single unified version of NetLogo will support both 2D and 3D modeling. We will be sure to design the 3D world support in such a way that it doesn't get in the way when you are building 2D models.

Models built in NetLogo 3D preview releases may require changes in order to run in the eventual unified version.

Are old versions of NetLogo still supported?

Yes. We still support NetLogo 1.3.1 (for Mac OS 8 and 9 and Windows 95 users), NetLogo 2.0.2, NetLogo 2.1, NetLogo 3.0.2, and NetLogo 3.1.5, and we will continue to support them as long as people are still using them.

There may be further point releases in the 3.1.x series if users report bugs or compatibility issues that need fixing.

To avoid overwhelming users with options, the download page on the NetLogo site offers only a limited selection of past releases (namely, the versions listed above), but if you need a specific point release not on the list, contact us and we'd be happy to provide it.

Downloading

The download form doesn't work for me. Can I have a direct link to the software?

Please write us at bugs@ccl.northwestern.edu and we'll either fix the problem with the form, or provide you with an alternate method of downloading the software.

Downloading NetLogo takes too long. Is it available any other way, such as on a CD?

At present, no. If this is a problem for you, contact us at feedback@ccl.northwestern.edu.

I downloaded and installed NetLogo but the Models Library has few or no models in it. How can I fix this?

So far, users reporting this problem all used the "without VM" download option for Windows. Uninstall NetLogo and try the "with VM" download instead.

Even if the "with VM" download fixes it for you, please contact us at bugs@ccl.northwestern.edu so we can find out more details about your setup. We'd like to fix this in a future version, but to troubleshoot it we need help from users.

Can I have multiple versions of NetLogo installed at the same time?

Yes. When you install NetLogo, the folder that is created contains has the version number in its name, so multiple versions can coexist.

On Windows systems, whichever version you installed last will be the version that opens when you double click a model file in Windows Explorer. On Macs, you can control what version opens via "Get Info" in the Finder.

I'm on a UNIX system and I can't untar the download. Why?

Some of the files in the tarball have very long pathnames, too long for the standard tar format. You must use the GNU version of tar instead (or another program which understands the GNU tar extensions). On some systems, the GNU version of tar is available under the name "gnutar". You can find out if you are already using the GNU version by typing tar --version and seeing if the output says "tar (GNU tar)".

How do I install NetLogo unattended?

It depends on which platform you are using.

I downloaded the without-Java Windows installer. Why won't NetLogo start?

We recommend the normal Windows download, which includes bundled Java. If you're having trouble with the alternate download that does not include bundled Java, see the requirements section for details.

Applets

I tried to run one of the applets on your site, but it didn't work. What should I do?

Current versions of NetLogo require that your web browser support Java 1.4.1 or higher. For more details about Java requirements see the Applet guide

Some NetLogo applets may require more memory than the browser normally makes available. See the memory section of the Applet guide for details on how to change the memory allocation.

Can I make my model available as an applet while keeping the code secret?

No. In order for the applet to operate, the model file must be accessible also.

When you use "Save as applet" on the File menu, the HTML page generated contains a link where the user can download the model file. If you want, you can remove that link. Doing so will make it harder for the user to access the model file, but not impossible.

Can a model saved as an applet use import-world, file-open, and other commands that read files?

Yes, but only to read files that are stored in the same directory on your web server as the HTML and model files. Applets cannot read files on the user's computer, only the web server.

When running my model as an applet, I get the following error: java.lang.OutOfMemoryError: Java heap space.

The Java Plug-In is not allocating sufficient space to run the model. Details on how big a model can be in NetLogo can be found here. You will need to increase the amount of memory available to the Java Plug-In. See the instructions here

When I tried loading my model as an applet I get an error like: java.lang.ClassFormatError: Incompatible magic value.

If your web server returns custom error messages in response to requests for non-existent pages it must also return a status code of 404 Not Found, otherwise, NetLogo thinks the following data is what it requested and tries to read it as such. This happens even if all the files required to run the applet are present.

If you don't have control over the error messages on your web server you can use the following as a workaround:

Note that all the directory and file names are case sensitive and should be created exactly as written.

Running

Can I run NetLogo from a CD?

Yes. NetLogo runs fine on a read-only file system.

Why is NetLogo so much slower when I unplug my Windows laptop?

Your computer is switching to power saving mode when unplugged. It's normal for this to reduce speed a little, but unfortunately there is a bug in Java that drastically slows down Swing applications, including NetLogo.

One workaround is to change the power settings on your computer so it doesn't go into power saving mode when you unplug it. (If you do this, your battery won't last as long.)

Another workaround is to run NetLogo with an option recommended by Sun, by editing the NetLogo.lax file, found in the NetLogo directory (under Program Files on your hard drive, unless you installed NetLogo in a different location). Edit this line:

lax.nl.java.option.additional=-Djava.ext.dirs= -server -Dsun.java2d.noddraw=true
and add -Dsun.java2d.ddoffscreen=false at the end of the last line.

You can see the details of the Java bug and vote for Sun to fix it here.

How come NetLogo won't start up on my Linux machine?

Ideally, any Java runtime version 1.4.1 or greater will run NetLogo. However, some Java implementations do not support features which NetLogo uses, such as Java2D and Swing. An example is the GNU libgcj based runtime on Linux, which comes preinstalled on some Linux distributions; NetLogo does not work with this runtime.

We recommend Sun's Java runtime when using NetLogo on Linux. (IBM's may also work.)

Ubuntu users should consult https://help.ubuntu.com/community/Java.

When I try to start NetLogo on Windows I get an error "could not create Java virtual machine". Help!

We're not certain there is only one possible cause for this message, but one possible cause we are aware of is a bug in Windows XP Service Pack 2 (and perhaps other Windows versions such as Windows Server 2003) which does not allow the allocation of large amounts of contiguous virtual memory on some machines.

A possible fix is to use a text editor to edit the NetLogo 4.0.5.lax file (found in the NetLogo directory, by default in C:\Program Files):

#   LAX.NL.JAVA.OPTION.JAVA.HEAP.SIZE.MAX
#   -------------------------------------
#   allow the heap to get huge

lax.nl.java.option.java.heap.size.max=900000000

Try changing the 900000000 to a smaller number such as 500000000. It may not be necessary to drop the memory allocation so drastically, you may want to experiment with decreasing the number more slowly to start. This should permit NetLogo to start, although the lower heap size limit may affect your ability to run models with very large numbers of agents. (See How big can my model be?.)

Another possible fix you could try, though we can't be certain it would help, is to upgrade to Windows Vista, or to Windows XP Service Pack 3 when it becomes available (as of November 2007 it is not yet available).

Can I run NetLogo from the command line, without the GUI?

Yes. The easiest way is to set up your model run as a BehaviorSpace experiment. No additional programming is required. See the BehaviorSpace section of the User Manual for details.

Another option is to use our Controlling API. Some light Java programming is required. See the "Controlling" section of the User Manual for details and sample code.

Does NetLogo take advantage of multiple processors/cores?

Not for a single model run, no. The NetLogo engine is single threaded and we expect it to remain that way. We don't have any plans to make it possible to split a single model run across multiple processors or multiple computers.

One way to take advantage of multiple processors, or multi-core processors, to do multiple model runs concurrently by running more than one instance of NetLogo simultaneously, each in its own Java virtual machine:

In a future version of NetLogo, we hope to improve the support for multiple processors/cores as follows:

Can I distribute NetLogo model runs across a cluster of computers?

Many of the same comments in the previous answer apply. It is not possible to split a single model run across multiple computers, but you can have each machine in a cluster doing one or more separate, independent model runs, using either BehaviorSpace or our Controlling API.

Numerous users are already using NetLogo on clusters. You can seek them out on the NetLogo Users Group.

I want to try HubNet. Can I?

Yes. There are two types of HubNet available. With Computer HubNet, participants run the HubNet Client application on computers connected by a regular computer network. In Calculator HubNet, created in conjunction with Texas Instruments, participants use Texas Instruments graphing calculators and the TI-Navigator Classroom Learning System.

See the HubNet section of the user manual for more details on Calculator HubNet for TI-Navigator.

For more information on HubNet in general, see the HubNet Guide.

Is there any way to recover lost work if NetLogo crashes or freezes?

Yes. NetLogo auto-saves files as you are working on them. The auto-save files can be found in your OS-specific temporary directory. On most Unix-like systems (including MacOS) that is /tmp. On Windows XP, logs can be found in C:\Documents and Settings\<user>\Local Settings\Temp, where <user> is the logged in user and on Windows Vista the logs can be found in C:\Users\<user>\AppData\Local\Temp. The files are named according to the following format: autosave_yyyy-MM-dd.HH_mm_ss.nlogo where the time and date are the time and date the model was opened.

Usage

When I move the speed slider all the way to the right, why does my model seem to stop?

The only way NetLogo can make your model run faster is by updating the view less frequently. As you move the speed slider to the right, view updates become less and less frequent. Since view updates take time, that means more speed.

However, fewer updates also means that the updates come farther apart. When several seconds pass between updates, it may seem like your model has stopped. It hasn't. It's running at full speed. Watch the tick counter! (If your model uses it. If it doesn't, watch something else, such as a plot.)

To get a feel for what's going, it may help to gradually move the slider to the right, rather than moving it all the way to the right all at once. If you find the updates too infrequent at the rightmost position, don't push the slider that far.

How do I change how many patches there are?

Press the Settings... button in the toolbar on the Interface tab. A dialog will appear in which you may change the dimensions of the world.

A quicker method is to use the three sets of black arrows in the upper left corner of the 2D view.

Can I use the mouse to "paint" in the view?

NetLogo does not have a built-in set of painting tools for painting in the view. But with only a few lines of code, you can add painting capability to your model. To see how it's done, look at Mouse Example, in the Code Examples section of the Models Library. The same techniques can be used to let the user interact with your model using the mouse in other ways, too.

Another possibility is to use a special drawing model such as the Drawing Tool model by James Steiner which is available from http://ccl.northwestern.edu/netlogo/models/community/.

A third possibility is to create an image in another program and import it. See the answer to Can I import a graphic into NetLogo?.

How big can my model be? How many turtles, patches, procedures, buttons, and so on can my model contain?

We have tested NetLogo with models that use hundreds of megabytes of RAM and they work fine. We haven't tested models that use gigabytes of RAM, though. Theoretically it should work, but you might hit some limits that are inherent in the underlying Java VM and/or operating system (either designed-in limits, or bugs).

The NetLogo engine has no fixed limits on size. By default, though, NetLogo ships with a one-gigabyte ceiling on how much total RAM it can use.

Here's how to raise the limit if you need to:

Can I import GIS data into NetLogo?

Yes. Try the GIS extension (new in NetLogo 4.0.3); see the GIS section of the User Manual.

A simpler way is to use import-pcolors, but that only works for importing maps that are images, not maps in other formats.

It is also possible to write NetLogo code that reads GIS data using our file I/O primitives such as file-open.

My model runs slowly. How can I speed it up?

Here's some ways to make it run faster without changing the structure of the code:

In many cases, though, if you want your model to run faster, you may need to make some changes to the code. Usually the most obvious opportunity for speedup is that you're doing too many computations that involve all the turtles or all the patches. Often this can be reduced by reworking the model so that it does less computation per time step. If you need help with this, if you contact us at feedback@ccl.northwestern.edu we may be able to help if you can send us your model or give us some idea of how it works. The members of the NetLogo Users Group may be able to help as well.

Note that using run and runresult are much slower than running code directly; you should avoid using these primitives in performance-critical code.

Can I have more than one model open at a time?

One instance of NetLogo can only have one model open at a time. (We plan to change this in a future version.)

You can have multiple models open by opening multiple instances of NetLogo, though. On Windows and Linux, simply start the application again. On a Mac, you'll need to duplicate the application in the Finder, then open the copy. (The copy takes up only a very small amount of additional disk space.)

Can I change the choices in a chooser on the fly?

At present, no. In a future version of NetLogo, we plan to support this.

Can I divide the code for my model up into several files?

Yes, this is available on an experimental basis using the __includes keyword.

Programming

How is the NetLogo language different from the StarLogo and StarLogoT languages? How do I convert my StarLogo or StarLogoT model to NetLogo?

We don't have a document that specifically summarizes the differences between these programs. If you have built models in StarLogo or StarLogoT before, then we suggest reading the Programming Guide section of this manual to learn about NetLogo, particularly the sections on "Ask" and "Agentsets". Looking at some of the sample models and code examples in the Models Library may help as well.

If you need any help converting your StarLogo or StarLogoT model to NetLogo, please feel free to seek help on the NetLogo Users Group. You may also ask us for help at feedback@ccl.northwestern.edu.

How does the NetLogo language differ from other Logos?

There is no standard definition of Logo; it is a loose family of languages. We believe that NetLogo shares enough syntax, vocabulary, and features with other Logos to earn the Logo name.

Still, NetLogo differs in some respects from most other Logos. The most important differences are as follows.

Surface differences:

The last three differences are illustrated in the following procedure definitions:

most Logos NetLogo
to square :x
output :x * :x
end
to-report square [x]
report x * x
end

Deeper differences:

Of course, the NetLogo language also contains many additional features not found in most other Logos, most importantly agents and agentsets.

How come my model from an earlier NetLogo doesn't work right?

See the Transition Guide section of the User Manual for help.

Why does my code have strange characters in it?

Unfortunately, NetLogo may not work properly in locales other than "en". A locale is a setting which tells NetLogo which language you are using, as well as how to display dates and numbers. If you have problems with strange characters in code, you can force NetLogo to use an U.S. English locale by changing your Java options:

The java options are found in different locations depending on your platform:

Windows: Open NetLogo 4.0.5.lax in a text editor like Notepad and change this line:

lax.nl.java.option.additional=-Djava.ext.dirs= -server -Dsun.java2d.noddraw=true
add -Duser.country=US -Duser.language=en at the end.

Mac: Control-click on NetLogo 4.0.5.app and select "Show Package Contents" then open Contents -> Info.plist. Edit the VMOptions (under Root -> Java) and add: -Duser.country=US -Duser.language=en to the end of the list.

Other: Open the netlogo.sh script in a text editor and change the script to read:

java -server -Djava.library.path=./lib -Djava.ext.dir= -XX:MaxPermSize=128m -Xmx1024m -Duser.country=US -Duser.language=en -jar NetLogo.jar "$@"

In a future version of NetLogo we hope to support other languages and locales.

How do I take the negative of a number?

Any of these ways:

(- x)
-1 * x
0 - x

With the first way, the parentheses are required.

My turtle moved forward 1, but it's still on the same patch. Why?

If you have disabled wrapping at the world edges in your model, then the turtle might be at a world edge and unable to move any further. You can test for this using can-move?.

Assuming the turtle isn't hitting a world edge, moving forward 1 is only guaranteed to take a turtle to a new patch if the turtle's heading is a multiple of 90 (that is, exactly north, south, east, or west).

It's because the turtle might not be standing in the center of a patch. It might be near a corner. For example, suppose your turtle is close to the southwest corner of a patch and is facing northeast. The length of the patch diagonal is 1.414... (the square root of two), so fd 1 will leave the turtle near the northeast corner of the same patch.

If you don't want to have to think about these issues, one possibility is to write your model in such a way that your turtles always come to rest on patch centers. See next question.

How do I keep my turtles on patch centers?

A turtle is on a patch center when its xcor and ycor are integers.

You can move a turtle to the center of its current patch with either of these two equivalent commands:

move-to patch-here
setxy pxcor pycor

But you'll never need to do that if you never allow turtles off of patch centers in the first place.

The sprout command creates turtles on patch centers. For example:

ask n-of 50 patches [ sprout 1 [ face one-of neighbors4 ] ]

Another way for a turtle to start on a patch center is with a command such as this line of turtle code, which moves it to the center of a random patch:

move-to one-of patches

Once a turtle is on a patch center, as long as its heading always stays an exact multiple of 90 (that is to say, due north, east, south, or west), and as it long as it moves forward or back by integer amounts, it will always land on patch centers.

See Random Grid Walk Example, in the Code Examples section of the Models Library, to see these code snippets in use.

patch-ahead 1 is reporting the same patch my turtle is already standing on. Why?

See the answer two answers up. It's the same issue.

This might not be the meaning of "ahead" you were expecting. With patch-ahead, you must specify the distance ahead that you want to look. If you want to know the next patch a turtle would cross into if it moved forward continuously, it is possible to find that out. See Next Patch Example, in the Code Examples section of the Models Library.

How do I give my turtles "vision"?

You can use in-radius to let a turtle see a circular area around it.

Several primitives let the turtle "look" at specific points. The patch-ahead primitive is useful for letting a turtle see what is directly in front of it. If you want the turtle to look in another direction besides straight ahead, try patch-left-and-ahead and patch-right-and-ahead.

If you want the turtle to have a full "cone" of vision, use the in-cone primitive.

You can also find out the next patch a turtle would cross into if it moved forward continuously. See Next Patch Example, in the Code Examples section of the Models Library.

Can agents sense what's in the drawing layer?

No. If you want to make marks that agents can sense, use patch colors.

I'm getting numbers like 0.10000000004 and 0.799999999999 instead of 0.1 and 0.8. Why?

See the "Math" section of the Programming Guide in the User Manual for a discussion of this issue.

The documentation says that random-float 1 might return 0 but will never return 1. What if I want 1 to be included?

It really doesn't matter. Even if 1 were a possible result, it would only come up approximately 1 in 2^64 tries, which means you'd be waiting hundreds of years before it ever came up exactly 1.

Nonetheless, if you are convinced that it really must be possible to get 1, you can use precision to round your answer to a certain number of decimal places. For example:

print precision (random-float 1) 10
0.2745173723

(If you use this method, note that 0 and 1 are only half as likely to come up as other answers. To see why this is so, consider the case where you only keep one digit after the decimal point. Results between 0 and 0.5 get rounded to 0, but results between 0.5 and 1.5 get rounded to 1; the latter range is twice as large. If you want 0, 0.1, 0.2, ..., 0.9, and 1 to all be equally likely, an alternative is to write random 11 / 10; this gives all 11 answers with equal probability.)

How can I keep two turtles from occupying the same patch?

See One Turtle Per Patch Example, in the Code Examples section of the Models Library.

How can I find out if a turtle is dead?

When a turtle dies, it turns into nobody. nobody is a special value used in NetLogo used to indicate the absence of a turtle or patch. So for example:

if turtle 0 != nobody [ ... ]

You could also use is-turtle?:

if is-turtle? turtle 0 [ ... ]

Does NetLogo have arrays?

In the current version of NetLogo, lists are true linked lists, rather than having an array-based underlying implementation as in earlier NetLogo versions.

True arrays are available by using the array extension. See the Arrays & Tables section of the User Manual.

Does NetLogo have hash tables or associative arrays?

Yes, using the table extension. See the Arrays & Tables section of the User Manual.

How can I use different patch "neighborhoods" (circular, Von Neumann, Moore, etc.)?

The in-radius primitives lets you access circular neighborhoods of any radius.

The neighbors primitive gives you a Moore neighborhood of radius 1, and the neighbors4 primitive gives you a Von Neumann neighborhood of radius 1.

For Moore or Von Neumann neighborhoods of a larger radius, see Moore & Von Neumann Example in the Code Examples section of the Models Library.

How can I convert an agentset to a list of agents, or vice versa?

If you want the list in a particular order, use the sort or sort-by primitives. The Lists section of the Programming Guide explains how to do this. See also Ask Ordering Example, in the Code Examples section of the Models Library.

If you want the list in a random order, here's how:

[self] of <agentset>

Because all operations on agentsets are in random order, the resulting list is in random order.

To convert a list of agents to an agentset, use the turtle-set, patch-set, or link-set primitives.

How do I stop foreach?

To stop a foreach from executing you need to define a separate procedure that contains only the foreach, for example:

to test
  foreach [1 2 3] [
    if ? = 2 [ stop ]
    print ?
  ]
end

This code will only print the number 1. The stop returns from the current procedure so nothing after the foreach will be executed either. (If the procedure is a reporter procedure, use report instead of stop.)

On my computer sometimes distance and in-radius return the wrong answer. What's going on?

There is a bug in Sun's server VM (which NetLogo uses) that affects a small number of Windows users (depending on the particular CPU you have on your computer).

If you're not sure if you have this problem, run the Ants model (in the Models Library, under Sample Models -> Biology) and press the SETUP button repeatedly. The model may set up correctly the first few times, but if you have the bug, eventually the setup will fail (the food piles will not be located correctly).

If you run into this problem you can work around it by using the regular, client VM instead, or by using Java 6 (instead of the Java 5 which comes bundled with NetLogo).

To change to the client VM, open NetLogo 4.0.5.lax (in the NetLogo application folder) and remove -server from this line:

lax.nl.java.option.additional=-Djava.ext.dirs= -server -Dsun.java2d.noddraw=true

Note that using the client VM will make models run slower on your machine (but at least they'll work!)

Using Java 6 will give you both correct behavior and maximum speed. To use Java 6, download and install the Java 6 JDK from Sun. Note that you want the full JDK, not the JRE, because the JRE does not include the fast server VM. Once you have the Java 6 JDK installed, go to the NetLogo home page and download and install the alternate NetLogo download that does not include bundled Java. You'll find this alternate download where the download page says "Want to run NetLogo using a Java VM you have already installed yourself?". During the NetLogo install process, select your Java 6 installation when prompted.

BehaviorSpace

How do I measure runs every n ticks?

Use repeat in your experiment's go commands, e.g.:

repeat 100 [ go ]

to measure the run after every 100 model steps. Essentially you are making one experiment step equal 100 model steps.

I'm varying a global variable I declared in the Procedures tab, but it doesn't work. Why?

It's probably because your setup commands or setup procedure are using clear-all, causing the values set by BehaviorSpace to be cleared.

One possible workaround is to change your experiment's setup commands to preserve the value of the variable, e.g.:

let old-var1 var1
setup
set var1 old-var1

This works because even clear-all doesn't clear the values of local variables made with let

Another possible workaround is to change your model's setup procedure to use more specific clearing commands to clear only what you want cleared.

Why are some of my results cut off in Excel?

In some versions of Excel, spreadsheets can't have more than 256 columns. (See a Microsoft support article on the subject.)

Possible workarounds include:

Extensions

I'm writing an extension. Why does the compiler say it can't find org.nlogo.api?

You need to add NetLogo.jar to your classpath when compiling. NetLogo.jar is included with NetLogo.