"You can't use TICK in a turtle context, because TICK is observer-only." - 不知道如何修复该错误

"You can't use TICK in a turtle context, because TICK is observer-only." - Don't know how to fix that error

我正在尝试创建一个自己的生态系统并且已经编写了大约 100 行代码。但我目前收到一条烦人的错误消息 [Title] 我无法摆脱,除非我使用 «Tick» 命令删除该行。

这就是界面的样子at the moment

这就是界面的样子after the latest successful simulation

这是有缺陷的代码:

turtles-own [saturation age gender]
breed [sheep a-sheep]
sheep-own [love-cooldown-sheep-f love-cooldown-sheep-m age%-sheep]
globals [tick-stopper]
patches-own [Next-to]

to setup
  clear-all
  setup-patches
  setup-sheep
  set tick-stopper 0
  reset-ticks
end

to setup-patches
  ask patches [ set pcolor green ]
end

to setup-sheep
  create-sheep number_of_sheep [set saturation max-saturation-sheep set gender random 2 set shape "sheep" set age 0]
  if setup-sheep-random-age? [
    ask turtles with [shape = "sheep"] [set age random life-exp.-sheep]
  ]
  ask turtles with [shape = "sheep"] [
    setxy random-xcor random-ycor
    if gender = 0 [
      set color 118
    ]
    if gender = 1 [
      set color 98
    ]
  ]
end

to go
  if tick-stopper >= stop-at-tick and stop-at-tick? [
    set tick-stopper 0
    stop
  ]
  move-sheep
  sheep-eat-grass
  make-love-sheep
  check-death-sheep
  regrow-grass
  set tick-stopper tick-stopper + 1
  tick
end

to move-sheep
  ask turtles with [shape = "sheep"] [
    right random 60
    left random 60
    forward 1
    set saturation saturation - 1
    set age age + (((random life-exp.-sheep) + 1) / ((life-exp.-sheep + 1)/ 2))
    if gender = 0 and love-cooldown-sheep-f > 0 [
      set love-cooldown-sheep-f love-cooldown-sheep-f - 1
      set saturation (saturation - (saturation-loss-til-birth-sheep / contribution-period-sheep))
      ]
    ]
    if gender = 1 [
      if love-cooldown-sheep-m > 0 [
        set love-cooldown-sheep-m love-cooldown-sheep-m - 1
    ]
  ]
end

to sheep-eat-grass
  ask turtles with [shape = "sheep"] [
    if pcolor = green and saturation < max-saturation-sheep [
      set pcolor brown
      set saturation saturation + saturation-from-grass
    ]
    ifelse show-saturation?
      [ set label saturation ]
      [ set label "" ]
  ]
end

to make-love-sheep
  ask turtles with [shape = "sheep"] [
    if gender = 0 and love-cooldown-sheep-f = 1 [hatch 1 [set saturation birth-saturation-sheep set gender random 2 set age 0
      if gender = 0 [set color 118]
      if gender = 1 [set color 98]
    if gender = 1 and love-cooldown-sheep-m = 0 and saturation > saturation-for-love-sheep and 1 = count turtles with [shape = "sheep" and gender = 0 and love-cooldown-sheep-f = 0 and saturation > saturation-for-birth-sheep] in-radius 1 [
      set saturation saturation - saturation-loss-at-love-sheep
      set love-cooldown-sheep-m cooldown-for-love-sheep
      ask turtles with [shape = "sheep"] in-radius 1 [
        if gender = 0 and saturation > saturation-for-birth-sheep and love-cooldown-sheep-f = 0 [set love-cooldown-sheep-f contribution-period-sheep]
          ]
        ]
      ]
    ]
  ]
end

to check-death-sheep
  ask turtles with [shape = "sheep"] [
    set age%-sheep (100 * (age / life-exp.-sheep))
    if saturation <= 0 [die]
    if age%-sheep < 22.5039287 [
      if (10 ^(0.00984 *(age%-sheep ^ 2) - 0.25918 * age%-sheep + 2.922))/ life-exp.-sheep > random 10000 [die]
    ]
    if age%-sheep > 156.24733 [
      if 10000 / (life-exp.-sheep / 100) > random 10000 [die]
    ]
    if age%-sheep > 22.5039287 and age%-sheep < 156.24733 [
      if (10 ^(1.899801588 -(((16 / 75 * (age%-sheep ^ 3)) - (50 * (age%-sheep ^ 2))) / 131250)))/ life-exp.-sheep > (random 10000) [die]
    ]
  ]
end

to regrow-grass
  ask patches with [pcolor = brown] [
    set next-to count neighbors4 with [pcolor = green]
    if (random 1000000 / 10000) <= (grass-growth% * count neighbors4 with [pcolor = green]) [set pcolor green]
  ]
end

感谢您的帮助<3 这是我使用 NetLogo 6.0.4 的第一个项目,在此之后不打算启动任何其他项目。

您的放羊过程中存在括号问题。你有这样的结构:

to move-sheep
  ask turtles with [shape = "sheep"]
  [ right random 60
    ...
    if gender = 0 and love-cooldown-sheep-f > 0
    [ 
    ]
  ]
  if gender = 1
  [ if love-cooldown-sheep-m > 0
    [ set love-cooldown-sheep-m love-cooldown-sheep-m - 1
    ]
  ]
end

所以你在处理 if gender = 1 之前不小心关闭了 ask turtles。一旦你有 if gender = 1 然后它切换到海龟上下文。