netlogo - 我可以根据比较变量值的结果将乌龟指向特定的补丁吗?
问题描述
解决方案
patch-group-id is a variable owned by patches and group-id is owned by turtles. So you need to tell NetLogo which group-id the patches are trying to match to. Try this:
ask turtles
[ let target one-of patches with [patch-group-id = [group-id] of myself]
]
Another way to do this is to drop the idea of group-id and simply have each turtle remember its home patch. Conceptually, this implements the idea that a group is entirely defined by its home patch. So your setup would look something like:
turtles-own
[ my-home
]
to setup
clear-all
ask n-of n-groups patches
[ sprout turtles 25
[ set my-home patch-here
]
set pcolor gray
]
end
Then you never need to construct the target, you simply get then to go to their variable my-home.
If you went down this path, you would also need to change the code that uses group-id. For example, you said that sometimes the turtles change their group-id, instead of set group-id [group-id] of ...
you would have set my-home [my-home] of ...
推荐阅读
- list - 如何在 Tcl 中的单词之间赋予动态变化的空间?
- c# - 当前类别名
- java - 为什么此输出由以下代码生成,为什么不生成错误/异常?
- java - 迁移到用于 Win 64 位 && 32 位 DLL 的 OpenJDK (amazon-corretto)
- google-sheets - 可以使用 importXML() 从 SERP 中抓取数据吗?
- python - 如何在scrapy python中跳过重复项
- javascript - 如何使用 Vue.JS 添加属性
- laravel - Laravel 将表单呈现为空
- python - 如何在python中解码json unicode字符串?
- c# - 更新字典值将行添加到 DataGrid WPF