문제

How does one access the link object at the current location of a turtle? For instance to count the number of times an event occurs while traversing a particular link.

I had (perhaps stupidly) assumed that you could:

ask link(s)-here [set count count + 1]

But link-here is not a method and that doesn't work.

Any advice much appreciated
Many thanks for reading.

Stephen

도움이 되었습니까?

해결책

Are your turtles just wandering around the plane and sometimes happen to cross over some links? If so, see Bryan's answer.

Or, are your turtles actually intentionally walking along the links? If the latter, then add:

turtles-own [current-link]

and at the time the turtle chooses the link and begins following it, store the link in that variable.

다른 팁

This answer shows how to get the distance to a link: https://stackoverflow.com/a/22163018/145080

You could then do something like:

to-report links-here
  report links with [ link-distance [pxcor] of myself [pycor] of myself < .5 ]
end

Note that this won't detect links passing through the edges of the patch. Play with the distance (currently .5) to get how you want it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top