Reputation: 385
I would like to change the color of the links that join one agent (reader's breed) to other readers that have a flag (TM? = true
). The code is something like this:
breed [ readers reader ]
undirected-link-breed [ rris rri ]
readers-own [ TM? ]
to start-TM [ ?reader ]
ask ?reader [
if any? other readers with [ TM? = true ] [
let other-TM-readers other readers with [ TM? = true ]
ask my-rris with [other-TM-readers] [ set color red ]
]
]
end
which returns me an error in the line ask my-rris with [other-TM-readers] [ set color red ]
because with
is expecting true or false and not an agentset.
How could I select the rri
links that connects current ?reader with the readers that have TM? = true
?
Regards
Upvotes: 1
Views: 341
Reputation: 14972
When you write:
let other-TM-readers other readers with [ TM? = true ]
you tell NetLogo to assign the agentset of all the readers for which TM
is true to the other-TM-readers
variable. So when you then write:
ask my-rris with [other-TM-readers] [ set color red ]
you are passing the other-TM-readers
agentset to with
, just like NetLogo is saying in its error message.
This is easy to fix, but first, a comment: writing = true
is almost always superfluous. Your TM?
variable is already a boolean, so you can check for it directly by writing with [ TM? ]
instead of with [ TM? = true ]
.
Now, to fix the error, you can write:
let other-TM-readers other readers with [ TM? ]
ask other-TM-readers [
ask rri-with myself [ set color red ]
]
or just:
ask other readers with [ TM? ] [
ask rri-with myself [ set color red ]
]
You could also ask the links directly, and use the other-end
primitive to check the color of the neighbors:
ask my-rris with [ [ TM? ] of other-end ] [ set color red ]
That last version is also safer than the previous versions, because it does not assume that there is a link between the caller and the other readers: it will only ask the links that are actually present. (The first two versions could check that rri-with myself != nobody
, but that would be less elegant.)
Upvotes: 2