请检查此代码。哪部分是错的
to catch-lizards
let prey one-of lizards-here
ifelse prey = "lizard2"
[ show "WRONG" ask prey [die]
set lifetime = lifetime + hawks-life-gain ]
[ifelse droping-tail? = true
[ask prey [set shape "lizard2"
set lifetime lifetime + hawks-life-gain / 4 ] ]
[ask prey [die]
set lifetime lifetime + hawks-life-gain ]
]
]
end
问题出现在哪里(显示“错误”)被写入。那部分不执行。语法不正确吗?
答案 0 :(得分:1)
在ifelse prey = "lizard2"
部分中,您可以比较prey
是否字符串lizard2
。但是猎物不是字符串,它是具有某些属性的对象,如shape
或lifetime
。
所以你需要问一下猎物的形状是lizard2
。
更新:检查猎物的形状可能如下所示:
ask prey [
ifelse shape = "lizard2" [
…
] [
…
]
]