Netlogo 中括号放置和 ifelse 和 let 命令的问题

Trouble with bracket placement and the ifelse and let commands in Netlogo

我在 Netlogo 中遇到括号放置和 ifelse 和 let 命令的问题。

我有各种不同的条件,这些条件与 patches-own (envi) 和 turtles-own (niche-opt, niche-range) 变量有关,这些变量确定局部变量 (multi),然后将用于确定繁殖概率。

海龟有一个变量 niche-opt,如果它匹配补丁变量 envi 那么局部变量 multi = 1

如果 niche-opt != envi 但 envi 在 niche-opt +- niche-range(turtle 变量,整数范围为 1 - 3)内,则 multi = 0.8

最后,如果 envi 在 niche-opt +- niche-range 之外,则 multi = 0.2

所以局部变量"multi"可以是三个值(1,0.8或0.2)之一,然后乘以海龟自己的变量(trait-2)并用于确定概率孵化发生。

我的问题是在代码行中:

if random-float 100 < (multi * trait-2 * 100)

出现错误 "nothing named multi defined"。我确定问题与我的括号放置有关,因为 let 创建了一个局部变量,但我不知道我是否需要添加更多括号或只移动我拥有的括号。

to go
   ask turtles [
   reproduce  
   ]
end

to reproduce  
  ifelse niche-opt = envi  
  [let multi 1] 
  [ifelse envi >= (niche-opt - niche-range) and envi <= (niche-opt + niche-range)
  [let multi 0.8]
  [let multi 0.2]
  ]
if random-float 100 < (multi * trait-2 * 100)
hatch 1 
end

使用起来可能是最简单的ifelse-value:

to reproduce  
  let multi ifelse-value (niche-opt = envi)[1] [
    ifelse-value (envi >= (niche-opt - niche-range) and envi <= (niche-opt + niche-range)) [0.8][0.2]
  ]
  if random-float 100 < (multi * trait-2 * 100) [hatch 1]
end

未测试。