Search code examples
syntax-errorsimulationnetlogo

NetLogo error: command expected, i cannot seem to find what is wrong with the code..?


to schooling
  set schoolmates other turtles in-radius 5
  if any? schoolmates 
  [ set nearestNeighbour min-one-of schoolmates [distancemyself]
    ifelse distance nearestNeighbour < 1
    [
      face nearestNeighbour
      right 180
    ]
    [
      rt subtract-headings averageHeading schoolmates heading subtract-headings
    ]
  ]
end

Does anybody know why i get this error here? I do not seem to have wrongfully placed brackets..


Solution

  • The problem is in this line.

    rt subtract-headings averageHeading schoolmates heading subtract-headings
    

    The first part

    rt subtract-headings averageHeading schoolmates
    

    is a command in itself so, when Netlogo finishes interpreting it, NetLogo looks for the next command. But

    heading subtract-headings
    

    is not a command, just some leftover "stuff". Might it have been mistyped or left over from a previous edit?