Netlogo 如何避免 NOBODY 运行时错误?

Netlogo How to avoid NOBODY Runtime error?

如何避免 NOBODY 运行时错误?以下是示例代码。这是一个可用于零除法错误避免的代码。因此,我知道它不能用于避免 NOBODY 错误。但我找不到任何其他方法。以下是运行时错误消息-> "IFELSE-VALUE expected input to be a TRUE / FALSE but got NOBODY instead." 感谢您的建议。

  set top ifelse-value (nobody)
  [ 0 ][ top ]
  set ts turtles with [speed = 0 and not right-end] 
  set top max-one-of turtles [who]
  set topx [xcor] of top ; A NOBODY error appears in "of" of this code
  set L count ts with [xcor > topx]

ifelse-value 的输入需要是 returns truefalse 的报告者(详细信息 here。因此,如果您使用nobody 作为输入,Netlogo 不会评估输入是否为 nobody,它只是读取 nobody- 换句话说,您的输入是 not 返回 truefalse

然后,对于输入,您需要使用一个布尔变量(一个 truefalse),一个 to-report returns truefalse,Netlogo 可以评估的表达式等。考虑以下示例:

to go

  let x true
  set top ifelse-value ( x ) 
  ["x is true"] 
  ["x is NOT true"]
  print ( word "Example 1:  " top )

  set top ifelse-value ( this-is-true ) 
  ["Reporter returned true"] 
  ["Reporter did not return true"]
  print ( word "Example 2:  " top )

  set x nobody
  set top ifelse-value ( x = nobody ) 
  ["x IS nobody"] 
  ["Is NOT nobody"]
  print ( word "Example 3:  " top )

  set x 0
  set top ifelse-value ( x = nobody ) 
  ["x IS nobody"] 
  ["x Is NOT nobody"]
  print ( word "Example 4:  " top )

  set top ifelse-value ( nobody = nobody ) 
  ["nobody = nobody"] 
  ["nobody != nobody"]
  print ( word "Example 5:  " top )

end

to-report this-is-true
  report true
end