Getting Started With NetLogo
Written by Mike James   
Monday, 11 March 2013
Article Index
Getting Started With NetLogo
Many Agents
Patches and Agent Sets
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.

 

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

 

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

 

blog comments powered by Disqus

 

Banner
 



Last Updated ( Monday, 11 March 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.