dhs227
dhs227

Reputation: 47

add a patch to an agentset and remove a patch from an agents

I have questions regarding netlogo agentset operation looking for help, thx.

  1. I want to add a patch, say patch-here, to a global agentset variable: mypatches. What is the correct way to write in a turtle procedure? I tried the following but it doesn't work:

    set mypatches (patch-set mypatches patch-here)
    
  2. I want to remove a patch, say patch-here, from a global agentset variable: mypatches. What is the correct way to write in a turtle procedure? The following code doesn't work because one-of operator assumes to remove self (which is a turtle) from mypatches but what I want is to remove patch-here from mypatches.

    set mypatches one-of mypatches
    

Upvotes: 1

Views: 1774

Answers (1)

bergant
bergant

Reputation: 7232

Appending patches

patch-set expects a patch agentset, so you have to initialize mypatches to an empty set before adding first patches:

set mypatches no-patches

Remove a patch

You can filter with with:

set mypatches mypatches with [[patch-here] of myself != self]

Maybe more elegant and not so "self-confusing" solution is to ask a patch-here to do it with other:

ask patch-here [set mypatches other mypatches]

Upvotes: 1

Related Questions