1

I have made a code for a land use change model but one part does not work properly. I'm not very experienced with Netlogo and and can't manage to find my mistake(s).

problem: the foreach part will not work although I copied it from the NETLOGO dictionary.

Netlogo dictionary (http://ccl.northwestern.edu/netlogo/docs/dict/foreach.html) gives:

(foreach list (turtle 1) (turtle 2) [3 4]
  [ [the-turtle num-steps] -> ask the-turtle [ fd num-steps ] ])
;; turtle 1 moves forward 3 patches
;; turtle 2 moves forward 4 patches

I re-wrote this to my own models needs but Netlogo then reports " expected an anonymous command here, rather than a list or block"

my code:

to go     
      ;; Sets Willingness to change true if patches are with more fellow patches than the scenario describes 

      (foreach list (Land-use = 1) (Land-use = 2) (Land-use = 3) (Land-use = 4) (Land-use = 5) (Land-use = 6) (Land-use = 7) [Senario1N Senario1L Senario1A Senario1B Senario1I Senario1R Senario1W]
      [ [the-Land-use the-Scenario] - >  ask patches [if count patches with [the-Land-use] > the-Scenario [ set Willingstochange True ] ] ])



      ;; Gives a score to atractivenesstochangein based on the ratio patches vs scenario 

        (foreach list (Land-use = 1) (Land-use = 2) (Land-use = 3) (Land-use = 4) (Land-use = 5) (Land-use = 6) (Land-use = 7) [Senario1N Senario1L Senario1A Senario1B Senario1I Senario1R Senario1W]
      [ [the-Land-use the-Scenario] - >  set atractivenesstochangein (count patches with [the-Land-use]/the-Scenario) ]

    end

But also when I use the exact Netlogo dictionary example Netlogo reports the same problem

Rdb
  • 21
  • 5

1 Answers1

2

There are multiple problems with this code. StackOverflow procedure is that you ask a separate question for each error that you are trying to fix. But this is more than just a procedure to assist other people trying to find answers to their problems, it is also related to good programming practice.

You need to code much more gradually. Write a piece of code, test it does what you want, fix it, then move on only once it works properly. It is much more difficult to debug when you have added a lot of code because it is no longer easy to work out where the error was introduced. This is even more important in NetLogo, where the interactions between elements can lead to subtle errors.

Having said that, I can at least identify some syntax problems.

1/ I have no idea what you mean by the 'iterations' part

2/ change procedure

ask patches [set Land-use (Land-use of Atractiveneigbor]

should be

ask patches [set Land-use ([Land-use] of Atractiveneigbor]

3/ setup-patches

Not sure, but I suspect this is about the ordering in your setup procedure. You run the load-gis procedure later than the setup-patches procedure. Your load-gis procedure starts with a clear-all command, which deletes everything you have already done.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thanks a lot for your help, I managed to solve the second and third problem! I've now edited my question so that it is focused on the first procedure and hopefully more clear about the iteration (foreach list statement) problem – Rdb Jun 11 '18 at 13:22