turtles-own [ a ]
patches-own [b ]
links-own [ c ]
to a+b
ask turtles with [ pxcor = x and pycor = y ][ set a + b ]
end
This works because a + b is added with the value of b at that patch coordinate.
I am trying to do the same thing with links.
turtles-own [ a ]
patches-own [b ]
links-own [ c ]
to a+b
ask turtles with [ pxcor = x and pycor = y ][ set a + b ]
end
This works because a + b is added with the value of b at that patch coordinate.
I am trying to do the same thing with links.
Short answer, you can't.
The reason that your example works (or would if you had set a a + b and provided values for x, y etc) is because you are asking turtles to do it (in NetLogo terms, done in turtle context). That is, a turtle is aware of its own 'a' value and has access to a unique 'b' value because the turtle is standing on one and only one patch. If you tried to do the same code with ask patches instead of ask turtles, you would get an error. This is because a patch cannot identify which of the potentially many turtles standing on it to provide the value for 'a'.
Since a turtle can be linked to any number of other turtles, it can have many links. That means there is not enough information for the turtle to know which link to provide the value of 'c'. But there are things you can do.
Option 1: randomly choose one of the links it is connected to
turtles-own [ a ]
links-own [ c ]
to a+b
ask turtles [ set a a + [c] of one-of my-links ]
end
Option 2: add up the 'c' values for all the links it's connected to
turtles-own [ a ]
links-own [ c ]
to a+b
ask turtles [ set a a + sum [c] of my-links ]
end
Or you could choose the largest value of 'c' etc.
To solve your coding problem you need to work out how the turtle should choose the link or links to provide the values that are to added.