netlogo 交通模拟编程帮助
我试图找出 patch-ahead n
上是否有一只乌龟,
其速度 - 加速度 <= 0。我想出的代码是:
if any? turtles on patch-ahead n with [speed <= (speed - acceleration)]
但这给出了一个错误:
patch-ahead 需要一个数字,而不是设置代理。
我该如何补救?
n 是一个数字变量。我想在调用乌龟的第 n 个补丁处访问乌龟的“速度”,这是用户定义的乌龟自己的变量。命令“with
”在这里不起作用。请建议一种替代方法来获取海龟的速度,例如,在调用海龟的第三个补丁处。
I am trying to find if there is a turtle on patch-ahead n
whose speed - acceleration is <= 0. The code I came up with is:
if any? turtles on patch-ahead n with [speed <= (speed - acceleration)]
but this gives an error that:
patch-ahead expects a number, instead got agent set.
How do I remedy this?
n is a number variable. I want to access the turtle's 'speed', which is a user defined turtle-own variable, at the nth patch from the calling turtle. The command 'with
' doesn't work here. Please suggest an alternative to access the speed of the turtle at, say, the 3rd patch from the calling turtle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 patch-ahead 文档,您会注意到它确实需要一个参数:一个代表前方距离的数字。您使用的是补丁“n”而不是数字。
根据您的评论,我认为您可能想要海龟,并使用括号使其更清晰,如下所示:
在上面我假设
n
是一个数字:您想要查看的距离前面。If you look at the patch-ahead documentation you will notice that it does require one argument: a number representing the distance to look ahead. You are using a patch 'n' instead of a number.
As per you comment, I think maybe you want turtles-on, and use parenthesis to make it clearer, as such:
In the above I am assuming that
n
is a number: the distance you want to look ahead.