如何在 NetLogo 中通过参数传递指令?

how can iI to pass an instrucction by param in NetLogo?

你好我有以下功能

to calc-col [x]
    ask x [set pcolor gray]
end

但我想要

to calc-col [x y]
    ask x y
end

这可能吗?

是的,尽管您的操作方式在 NetLogo 5.x 和 6.x (which is currently in beta) 之间有所不同。

在 NetLogo 5.x 中,您可以使用 tasks:

to calc-col [ x y ]
  ask x [ run y ]
end

然后你可以这样称呼它:calc-col some-agent task [ set pcolor grey ]

在 NetLogo 6.x 中,任务已被 anonymous procedures 取代。您 运行 它们以完全相同的方式(使用 runrun-result),但您使用新的 -> 语法定义它们:

calc-col some-agent [ [] -> set pcolor grey ]