Getting Started With NetLogo
Written by Mike James   
Thursday, 02 June 2022
Article Index
Getting Started With NetLogo
IDE
Ticks And Go
Variables

NetLogo is a remarkable language that is fine-tuned for particular types of application - agent-based simulation. Oh, yes, and did I mention it was Logo.

A Programmers Guide To Languages

languagecover

Contents

  1. Octave
  2. Scratch 3 *revised
  3. Node.js *revised
  4. App Inventor 2 *revised
  5. Getting Started With .NET IL
  6. NetLogo *revised
  7. Small Basic  *revised
  8. TypeScript *revised
  9. Google Apps Script
  10. Guide to F#
  11. Python
  12. Google's Go
    1. A Programmer's Guide To Go With Visual Studio Code *revised
    2. A Programmer's Guide To Go Part 2 - Objects And Interfaces *revised
    3. A Programmer's Guide To Go Part 3 - Goroutines And Concurrency *revised
  13. Guide to F#
  14. The Prolog Way ***NEW!
  15. Ruby
    1. Object-Oriented Approach
    2.    A Functional Language

If you think that this educational language died out, NetLogo demonstrates the inevitable truth that no computer language ever dies out!

NetLogo really is a language that deserves to be better known in the wider programming community simply because there are some applications that it is perfect for and not to use it would be taking the long way round. However, there a number of difficulties in getting started with it.

The first is that it is based on Logo and this presents a barrier to anyone not lucky enough to have encountered Logo at school, say. Logo isn't like the popular object-oriented languages that we are all so familiar with. It isn't really a functional language either. The best way to describe it is as a stack-oriented language, but I have no doubt that there are Logo enthusiasts who would take issue with this description.

The second big problem with learning NetLogo is that it is an agent-based simulation language. What this means is that you can create multiple agents very easily and get them to do things equally easily. NetLogo is a quasi parallel language - to be more precise its a simulated SIMD (Single Instruction Multiple Data) language. This makes it ideal for simulations where you have lots of similar agents doing similar things such as population studies, simulating gas molecules, traffic flows and so on. However, don't think that NetLogo is limited to the situations I have listed - it is a completely general purpose language with some special features.

Perhaps the third problem is the documentation. This is very good, but really doesn't give the beginner or the experienced programmer a very easy route into getting started with NetLogo - this is, I hope, where this article comes in. Its objective is, not to teach you the whole of NetLogo, but to simply get you started with the basic concepts and to get you to a point where the excellent documentation becomes useful to you.

The good news is that NetLogo is open source and it runs on Linux, Windows or Mac OS. Simply download, install and run - there should be no problems.

Running A Program

Assuming that you have NetLogo downloaded and running the first thing that you see is a window containing a menu, three tabs (more of which later) and a black window. All a bit mysterious with no real clue as to what to do next.

 

Start

 

If you look at the bottom of the Window you will see a horizontal panel and a text box labeled "observer". This terminology doesn't make much sense when you first meet it. In fact it s is just an immediate evaluation entry line. You can type in a line of code and it will be obeyed at once.

This means we can get "Hello World" out of the way at once. Simply type:

print "Hello World"

into the observer line and press return. You will see the message appear in the command center box above.

 

hello

 

Now we need to move on to a program that does a little more.

If you want to enter a long program then the command center isn't good way to do the job. The Code tab takes you to a code entry editor where you can build up larger programs. Everything you enter into to the code editor has to be in the form of a function. Logo functions are just like functions you will find in other languages but the syntax is slightly strange.

For example

to greet
  print "Hello World"
end

The name of the function is greet and the keyword to assigns the lines of code until you reach end.

So how do you run the code in a function?

One way is to simply type the function's name into the command center:

greet

 

You could write an entire NetLogo program as a function and run it from the command center in this way but this is not the most usual way of doing the job.

<ASIN:1871962536>

<ASIN:1871962587>

<ASIN:1871962544>

<ASIN:1871962552>



Last Updated ( Thursday, 02 June 2022 )