Is there a way to set up a patch-set based on a patch-variable in net logo?

I have a fairly simple question: is there a way to define a patch-set based on a patch-variable? In my model, I have a large set of patches that form the food object, and food is a patch-variable. I have the turtles change color when they find themselves on the food, but I have previously manually defined the patch-set on which they change color. However, I want to adjust the location of the food, and I don't want to go through the work of checking and redefining all the food patches. Thanks!!

to setup-food
  if (distancexy (0.8 * min-pxcor) (0.8 * min-pycor)) < 5
  [set food 5
    if food > 0
    [set pcolor cyan]]

TO look-for-food;; procedure that controls turtle color change on food
let potential-leaders foragers-on (patch-set patch -38 -16 patch -37 -16 patch -36 -16 so on..)
[do things]

1 answer

  • answered 2021-04-08 13:46 JenB

    you can create such a patch set explicitly like:

    let foods patches with [food > 0]
    ask foods [ set pcolor cyan ]

    This is a local variable that is thrown away (hence let) when the procedure is over, but you can also create a global variable if you are going to need this patchset in lots of places in your code, just remember to update it when the food runs out on a patch.

    And you also do this implicitly whenever you use with

    ask patches with [food > 0] [set pcolor cyan]