无法设置乌龟的平均标题,并显示错误消息“表示预期输入为列表,但获取的数字为XXX”

时间:2014-10-21 05:59:58

标签: netlogo

当他们找到最近的领导者时,我试图让乌龟转向平均领导者的标题,但是当运行代码时,此错误消息弹出“意味着预期输入是一个列表但是获得了数字XXX而不是“这是代码:

 [turn-towards average-heading-towards-leaders max-cohere-turn]

下面是我的完整代码:

to go
 ask turtles [check]
 tick
end

to check
 if leader? 
  [let beings-seen patches in-cone leader-vision leader-vision-angle with [pcolor = red] 
    ifelse any? beings-seen 
     [let target one-of beings-seen
    face target ] 
    [flock]]
end

to flock
 let nearby-leaders turtles with [leader? ]
 if any?  nearby-leaders in-radius vision
 [turn-towards average-heading-towards-leaders max-cohere-turn]
end

to-report average-heading-towards-leaders  
 let nearby-leaders turtles with [leader? ]
 let x-component mean [sin heading] of one-of nearby-leaders
 let y-component mean [cos heading] of one-of nearby-leaders
 ifelse x-component = 0 and y-component = 0
  [ report heading ]
  [ report atan x-component y-component ]
end

有人可以指出我的代码有什么问题。谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

问题在于这两行:

 let x-component mean [sin heading] of one-of nearby-leaders
 let y-component mean [cos heading] of one-of nearby-leaders

[sin heading] of one-of nearby-leaders报告附近一位领导人的标题正弦,这是一个单一的数字。 mean需要一份清单。所以你试图将一个数字传递给需要列表的东西。

要修复它,你可以摆脱这些行中的mean