+预期输入为数字,但取为TRUE / FALSE true

时间:2019-02-09 09:07:47

标签: netlogo

继续出现此错误,但变量不是true / false ...它们是数字。随附以下模型的完整代码。首先附有错误的部分,然后是整个代码(包括错误部分)

模型显示乌龟像母牛,斑块像草。该错误源于增长草函数,其中每个刻度线都使补丁增长指定的数量。以前可以使用,但是现在返回错误...

“ +预期输入为数字,但取为TRUE / FALSE true。”

to grow-grass
      ask patches [
        set grass-energy grass-energy + regrow-energy
      ]
    end


turtles-own [energy]
patches-own [grass-energy]


to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end

to scatter
  clear-turtles
  setup-turtles
end


to go
  if ticks >= time-limit [ stop ]
  move-turtles
  check-patches
  eat-grass
  grow-grass
  reproduce
  check-death
  tick
end

to move-turtles
  ask turtles [
  ifelse move-left?
  [ left random 45
    forward 1
    set energy energy - move-energy ]
  [ right random 360
    forward 1
    set energy energy - move-energy ]
  ]
end

to eat-grass
  ask turtles [
    if pcolor = green [
      set energy energy + energy-from-grass
      set grass-energy grass-energy - energy-from-grass
    ]
    ifelse show-energy?
    [ set label energy ]
    [set label "" ]
  ]
end

to reproduce
  ask turtles [
    if energy >= reproduce-energy [
      set energy energy - birth-energy
      hatch 1 [ set energy birth-energy ]]
  ]
end

to check-death
  ask turtles [
    if energy <= 0 [ die ]
  ]
end

to check-patches
  ask patches with [count turtles-here >= 2] 
  [ ask one-of turtles-here [ ask other turtles-here[set energy     energy - (energy / 2)]]]
end

to grow-grass
  ask patches [
    set grass-energy grass-energy + regrow-energy
  ]
end

to setup-patches
  ask n-of green-patches patches [ set pcolor green set grass-energy     grass-energy + grass-alive ]
  ask patches [ 
    if pcolor = black [ set pcolor brown set grass-energy grass-    energy = 0 ]
  ]
end

to setup-turtles
  create-turtles number [ setxy random-xcor random-ycor ]
  ask turtles [ set energy energy + birth-energy set shape "cow" set     size 1.5 ]
end

1 个答案:

答案 0 :(得分:1)

我认为问题出在您的setup-patches过程中,您在这里说:

set grass-energy grass-energy = 0

这会将grass-energy变量的值设置为表达式grass-energy = 0的值,该表达式报告truefalse

我认为您可能只想写set grass-energy 0

NetLogo使用set variable value而不是variable = value来更改变量的值有时会使来自其他语言的人感到有些困惑,但是通常很快就会习惯