Table of Contents
1. Creating the world |
2. Buttons and Procedures |
3. Sliders and Variables |
4. Creating Turtles and Patches |
5. Making the Model Go |
In this section, you will create a button that will be used to set up the model.
In the new menu that appears you can specify what the button should do.
You can see that the button is red which means it refers to a procedure (method, i.e. we will tell it to do something) that hasn't been created yet. We'll do that now.
One thing that hasn't been covered yet is procedures. These are a way of grouping several commands together that perform a common task. One example is setting up the model: there will probably be some commands to create the turtles, some for the patches, and some to create other parts of the model. We can group these all together in a single procedure.
We are going to create a new procedure called 'setup'.
to setup
print "Setting Up Model"
end
The code above does three things:
to setup
) says whatever comes next will be part of
a procedure called 'setup'.print "Setting Up Model"
) -
it will print a message to the command centre.end
) says that we have come to the end of the
'setup' procedure. Any more commands that come afterwards are not part of
'setup'.It's worth having another look at what is going on above, as this goes to the heart of how NetLogo works. The first thing that we did is create a button. When creating it, we told the button that if someone presses it, it should try to run a procedure called 'setup'.
Then, in the Code tab, we created a new procedure called 'setup'. So, if someone presses the button, all the commands that are part of the 'setup' procedure will run. The image below illustrates this graphically.
Have a go at the activities below. When you're comfortable that you can answer them, move on to part 3.