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

 

Variables

The last complication in getting to grips with NetLogo is the way variables work.

You can define a global variable that is available to every function using

globals [myVariable]

and you can then use myVariable to store a value using set. For example:

set myVariable=10

You can also create a local variable within a function using the let keyword:

let myLocalVariable=20

Local variables only exist after the let statement and if the let is within square brackets it only exists within those brackets.

Of course agents have variables and we have already been using many built in variables. You can also add your own variables to agents so that you can create custom states. Each type of agent has its own set of variables. You can add to the set of variables using something like:

turtles-own [myTurtleVariable]

This adds the new variable myTurtleVariable to every turtle. Each turtle gets its own separate new variable and can hold a value that is potentially different for all turtles. You can do the same for patches and links.

Notice that turtles and patched have a special relationship in that a turtle can access the variables of the patch it is "standing" on. For this reason turtles and patches cannot have a variable with the same name.

Where Next?

There is so much that we haven't covered. You need to learn about links, the third type of agent. You also need to find out more about general Logo - if, repeat, functions with parameters, and so on. NetLogo also has good facilities for building user interfaces and for presenting the results of simulations.

However, you have now been introduced to the main elements of the NetLogo language and what makes it special - and hence what makes it difficult to get started with.

 Start

 

 

More Information

NetLogo Website

Related Articles

Small Basic - The Programmer's Guide

Getting Started With TypeScript

Getting Started With Google App Script

Getting Started with Python

 

 

Banner

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

<ASIN:1871962536>

<ASIN:1871962587>

<ASIN:1871962544>

<ASIN:1871962552>

 



Last Updated ( Thursday, 02 June 2022 )