NetLogo 5.3.1,错误消息 "Expected ["

NetLogo 5.3.1, error message "Expected ["

我正在从 Railsback 和 Grimm 的一本名为“基于代理和基于个体的建模”的书中学习 ABM。根据这本书,他们走过的第一个完整模型如下所示:

 globals
turtles-own
[
  time-since-last-found
]
  num-clusters
]
[
  time-since-last-found
]

[
  num-clusters
]

to setup
  clear-all
  set num-clusters 4
  ask n-of 4 patches
  [
    ask n-of 20 patches in-radius 5
    [
    set pcolor red
    ]
  ]
  create-turtles 2
  [
    set size 2
    set color yellow
    set time-since-last-found 999
  ]
end

to go
  ask turtles [search]
  to search
    if-else time-since-last-found <= 20
    [right (random 181) -90]
    [right (random 21) -10]

    forward 1
    ifelse pcolor = red
    [
      set time-since-last-found 0
      set pcolor yellow
    ]
    [
      set time-since-last-found time-since-last-found + 1
    ]
  end

书上说我应该能够 运行 简单的 Mushroom Hunt 模型。但是,相反,我不断收到一条错误消息,提示我需要额外的 [ "Expected ["。

我不知道我需要把它放在哪里。更重要的是,在我看来我确实不需要它,我不明白为什么它说我需要。

谢谢!

阅读 Railsback 和 Grimm 时,查看 Netlogo Programming Guide 可能会有所帮助。它有助于概述正确的语法,并以不同的方式解释哪些代码需要放在什么地方。

您上面的代码存在几个问题 - 例如,查看 GlobalsTurtles-own。请注意方括号应如何包含每个块中的变量。接下来,查看所有过程如何以 to 开始并以 end 结束 - 您应该看到上面的 "go" 过程中嵌套了一个 "search" 过程。