0

Is it possible to write NetLogo in separate files as then import them like in java, python etc. or just call them like Matlab.

One may argue that NetLogo code normally doesn't get so huge for the above requirement. But since there is no ODE solving functionality and some other functions I require for my model I have had to write them on my own. This has increased my code length incredibly. Thus, I ask the question.

I don't know how this question makes sense as each code has an attached GUI with it. I am considering the possibility of writing a library but couldn't find any straight forward documentation for it.

Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142

1 Answers1

3

You can include multiple source files (.nls) in one NetLogo Model file (.nlogo). To do this, just add the primitive __includes [ ] at the beginning of your model code. After pressing the check button, a new button will appear next to the Procedures drop-down menu. There you can create and manage multiple source files. Details are also explained here: http://ccl.northwestern.edu/netlogo/docs/programming.html#includes

However, in order to make it work in a way like reuasable library files, one should create procedures which use agentsets and parameters as input variables to be independent of global definitions or interface settings.

nldoc
  • 1,179
  • 5
  • 6
  • Thanks! Makes my life way lot easier. – Abhishek Bhatia Jun 29 '15 at 19:59
  • In `code` tab I click on `includes` drop down, then a `New source file`. Now a new tab opens with `New File`. How do I name this file? – Abhishek Bhatia Jun 29 '15 at 20:09
  • 1
    The additional files should have .nls as file-ending, like "library.nls". You can also create empty txt files in your explorer window and rename them to "textfile.nls". Then you have to add the name of your saved file into the `__includes []` command. For example: `__includes ["library.nls"]`. Seperate multiple input files with spaces. – nldoc Jun 30 '15 at 06:48
  • thanks! But you suggested an alternate way. That didn't answer my question. – Abhishek Bhatia Jun 30 '15 at 12:02
  • 1
    Ok, perhaps I misunderstood your question. You name the file by saving it. When you changed the content of the empty source file (e.g. adding some code) and go to "File -> Save", netlogo will ask you to specify a location to save the source file. Same happens when you close the source file. The header of the appearing popup-window should be "Save NetLogo Source File". Define a filename with .nls ending and save it. Nevertheless, to persistently include it to your model you have to put the filename into the `__includes []` command manually as said above. Hope that helps? – nldoc Jun 30 '15 at 12:18
  • Thanks that helps! Though when I am saving the `.nls` `File>Save as` it tends to save the model `.nlogo` file I don't know why. – Abhishek Bhatia Jul 07 '15 at 16:09