这是您的代码,间距略有不同
foreach max-links
[ the-links ->
ask the-links
show [label] of [one-of my-out-links] of [end2] of the-links with [other-end = [end1] of the-links]
]
问题 1:您需要在“链接”被要求做的事情周围加上括号
问题 2:您在一行代码中有太多复杂的逻辑 - 没有括号可以提供帮助。如果你想调试,把它分成几个步骤,然后只有在它工作时才组合。另外,我怀疑“链接”是单个链接(因为它位于 foreach 中)而不是链接集,因此您应该给它一个单数名称以帮助您保持思路清晰。
所以:show [label] of [one-of my-out-links] of [end2] of the-links with [other-end = [end1] of the-links]
变成
let chosen-turtle [end2] of the-link with [other-end = [end1] of the-link]
let chosen-link [one-of my-out-links] of chosen-turtle
show [label] of chosen-turtle
把它分解成这样的步骤,很明显第一行没有意义。如果链接的other-end 是[end1] of the-link,那么您只是要求[end2] of the-link。
发现(可能的)问题后,固定代码是:
foreach max-links
[ the-link ->
ask the-link
[ let chosen-turtle [end2] of the-link
let chosen-link [one-of my-out-links] of chosen-turtle
show [label] of chosen-turtle
]
]
而且,如果这有效(我无法测试它),那么您可以根据需要将其放回一行。但是以多行开头,因为 NetLogo 会指向有问题的行,从而更容易调试。
foreach max-links
[ the-link ->
ask the-link
[ show [label] of [one-of my-out-links] of [end2] of the-link
]
]