NetLogo - Sandpile模型 - 错误 - 如果预期2个输入

时间:2015-03-30 19:41:25

标签: syntax-error netlogo

作为设置过程的一部分,我尝试使用滑块设置将显示的贴片密度并指定随机值。接口上的滑块用于密度范围0到100,并且使用接口上的输入设置补丁的随机值。这通常会在区域中设置为4.因此,如果设置了50%,则该过程将使用随机值分配50%的补丁。

当我这样做时,我得到以下错误:“如果预期2个输入,一个真/假和一个命令块”和“if(random-float 100.0)< init-errors”在代码中突出显示。

; The density of patches to be set with a random value is set using variable init-errors on interface.
;; Every patch uses a task which reports a random value.
;; The random value is set using variable error-count on interface
to setup-random
   ask patches [
     if (random-float 100.0) < init-errors
     setup task [ random error-count ]
   ]
end 

1 个答案:

答案 0 :(得分:0)

根据http://ccl.northwestern.edu/netlogo/docs/dictionary.html#if if的语法是:

if <condition> [ <commands> ]

方括号是强制性的,但是你把它们排除了,因此错误。 (方括号括起来的命令是&#34;命令块&#34;,因此错误&#34;期望...命令块&#34;。)