我收到一个错误,我的函数需要2个输入,但我确实放了两个输入

时间:2014-09-20 07:10:29

标签: function netlogo

我定义了以下功能:

 to-report J [ num1 num2 ] 
 ifelse (num1 = 3 or num2 = 3)  [report 16]
[ifelse (num1 = 1 and num2 = 1) [report 14]
 [ifelse (num1 = 2 and num2 = 2) [report 2]
   [ ifelse ((num1 = 1 and num2 = 2) or (num1 = 2 and num2 = 1 )) [report 11] 
      [report 0]
    ]
  ]
 ]

end

后来我在补丁程序中使用它,我将单元格类型定义为0或1作为补丁的变量,我像这样更新

 to update

   let c-t cell-type
   let c-t_1 [ cell-type ] of patch-at 1 0
   let energy_neighbors  J[ c-t c-t_1 ]   

end

它告诉我,J期待两个输入。即使在我的代码中我放了J [1 2],它仍然告诉我它需要两个输入。

如果我没有正确定义这个功能,有什么想法吗?或者正确地调用它?干杯!

1 个答案:

答案 0 :(得分:2)

括号是罪魁祸首!括号用于代码块和列表,但在调用过程时不用于参数。只需删除它们:

let energy_neighbors J c-t c-t_1