-1

I am trying to compare the local variables of a turtle, with its neighbors and trying to find out the total number of neighbors which match this criterion total-nearby = total number of neighbors. I am checking according to the color of the turtles, if the color is different, then I will check for the attributes/variables Error: A patch can't access a turtle or link variable without specifying which agent

CODE:

 turtle-own[
 total-similar-nearby     ; sum of previous two variables
total-other-nearby
total-nearby
  native
  language
  income
  maritalstatus
]
;;then assigning multiple number of turtles with different values to the local variables.

ask turtles[
repeat  total-nearby

    [
      if color = [color] of one-of neighbors
      [set d1 d1 + 1]
     if color != [color] of one-of neighbors 
    [
       if native = [ native ] of one-of neighbors
      [set a 1]
      if language = [ language ] of one-of neighbors
      [set b 1]
        if income = [ income ] of one-of neighbors
      [set c 1]
      if maritalstatus = [ maritalstatus ] of one-of neighbors
      [set d 1]
      
    ] set p  a  +  b + c  + d 
      if p >= 50 [set d1 d1 + 1]   
    ]
]
Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
  • 2
    Hi! Please make sure that your question satisfies what you can find [here](https://stackoverflow.com/help/how-to-ask) and [here](https://stackoverflow.com/help/minimal-reproducible-example), this will make it easier to help you. In this case, for example, the code you provided isn't enough to make a reproducible example of the problem. Ideally, you would provide a piece of code that everyone can copy+paste in their NetLogo and see the same error that you see, without writing any code. It is possible to see something wrong in the current example, but please edit your question for better clarity – Matteo Aug 29 '21 at 12:33
  • 1
    Supratim, I see you modified your post - however that was not a substantial change. You can try it yourself: if you create a brand new NetLogo file and then copy+paste the code that you wrote here, what do you get? You get something that does not compile. Can you share with us a working example of your code? i.e. one that, if we place it in a brand new NetLogo file, will show the error that you are asking about. – Matteo Aug 31 '21 at 15:33
  • I want to know is there a way, I can compare the local variables of a turtle with its neighbors? For each turtle, It will see if they have different colors, then they will compare their attributes – SUPRATIM MAITRA Sep 01 '21 at 13:23

1 Answers1

1

neighbors is a patch variable, not a turtle variable. So, the turtles in your model use the primitive neighbors, they are querying an agentset of patches when they want to query an agentset of turtles. There are several ways for turtles to evaluate nearby turtles, such in-radius or in-cone, but in this case if you're wanting the turtles that are specifically on the patches directly adjacent, you could use the other, turtles-on, and neighbors primitives to get what you're looking for. For a simple example, have a look at this toy model:

to setup
  ca
  ask n-of 300 patches [
    sprout 1 [
      set color one-of [ red blue ]
    ]
  ]
  reset-ticks
end

to go 
  ask turtles [
    ; Make an agent-set of turtles on neighboring patches
    let nearby-turtles other turtles-on neighbors
    
    ; If there are any turtles on neighboring patches, 
    ; assume the color from one of them.
    if any? nearby-turtles  [
      set color [color] of one-of nearby-turtles
    ] 
  ]
  tick
end

Check out the dictionary definitions for other, turtles-on, and neighbors for more information.

Luke C
  • 10,081
  • 1
  • 14
  • 21