Code Tab Guide

NetLogo 6.0.2 User Manual

The Code tab is where the code for the model is stored. Commands you only want to use immediately go in the Command Center; commands you want to save and use later, over and over again, are found in the Code tab.

screen shot

To determine if the code has any errors, you may press the "Check" button. If there are any syntax errors, the Code tab will turn red, the code that contains the error will be highlighted, and an error message will appear.

screen shot

Switching tabs also causes the code to be checked, so if you just switch tabs, pressing the Check button first isn't necessary.

To find a fragment of code in the procedures, click on the "Find" button in the Code toolbar and the Find dialog will appear.

screen shot

You may enter a word or phrase to find, and optionally also a new word or phrase to replace it with. The "Ignore case" checkbox controls whether the capitalization must be the same to indicate a match.

If the "Wrap around" checkbox is checked, the entire Code tab will be checked for the phrase, starting at the cursor position. When it reaches the end it will return to the top, otherwise only the area from the cursor position to the end of the Code tab will be searched. The "Next" and "Previous" buttons will move down and up to find another occurrence of the search phrase.

"Replace" changes the currently selected phrase with the replace phrase and "Replace & Find" changes the selected phrase and moves to the next occurrence. "Replace All" will change all instances of the find phrase in the search area with the replace phrase.

To find a particular procedure definition in your code, use the "Procedures" popup menu in the Code tab. The menu lists all procedures in alphabetical order.

The "Shift Left", "Shift Right", "Comment", and "Uncomment" items on the Edit menu are used in the Code tab to change the indentation level of your code or add and remove semicolons, which mark comments, from sections of code.

For more information about writing procedures, read Tutorial #3: Procedures and the Programming Guide.

Included Files Menu

Caution: The includes facility is new and experimental.

When you add the __includes keyword to a model a menu to the right of the procedures menu appears. This is the "Included Files" menu which lists all the NetLogo source files (.nls) included in this file. You can make this menu always visible using the Preferences dialog.

screen shot

You can choose a file name from the menu to open a tab for that file, or you can open a new or existing file using New Source File and Open Source File, respectively.

screen shot

Once you've opened new tabs they become accessible from the Tabs menu, and you can use the keyboard to move from tab to tab (Command + number on Mac, Control + number on other operating systems).

screen shot

Automatic indentation

When the Indent Automatically checkbox is selected, NetLogo will automatically attempt to align your code in a logically structured format. For example, when you open a set of square brackets "[" (perhaps after an if statement), NetLogo will automatically add spaces so that the following lines of code are two spaces further indented than the bracket. When you close the square brackets the closing bracket will be lined up with the matching open bracket.

screen shot

NetLogo will try to indent the code as you type, but you can also press the tab key anywhere on any line to ask NetLogo to indent the line immediately. Or, you can select a whole region of code and press the tab key to re-indent all of it.