user6054995
user6054995

Reputation:

Netlogo assign group of patches to own variable of a breed

I'm very new to netlogo and am wondering how I can set a group of patches to be an own variable to a certain breed. For example, let's say I have:

breed [ buildings building ]
buildings-own [ my-patches ]

I want to be able to have a set of patches (let's say a rectangle, so constrained by some coordinates) that are assigned to each individual building's my-patches field. How would I do this?

Upvotes: 1

Views: 1309

Answers (2)

Luke C
Luke C

Reputation: 10291

Welcome to Stack Overflow and Netlogo! Given your breed and buildings-own as above, you can simply use set to assign the patch-set that you want a building's my-patches variable to hold.

to setup
  ca
  ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
    sprout-buildings 1 [ 
      set shape "square"
      set heading 0
      set size 1.5
      set my-patches patches with [ 
        pxcor > [pxcor] of myself - 3 and
        pxcor < [pxcor] of myself + 3 and 
        pycor > [pycor] of myself - 3 and
        pycor < [pycor] of myself + 3
      ]
      ask my-patches [
        set pcolor [color] of myself - 2
      ]
    ]
  ]
  reset-ticks
end

Upvotes: 1

JenB
JenB

Reputation: 17678

First thing you need to know is that you can't have breeds of patches. While you don't say that's what you want, I just want to make sure you are aware of this.

Have a look at this code. It is a complete program that creates some turtles (called realtors) and assigns them each some patches. It then turns those patches the same colour as the realtor.

breed [realtors realtor]
realtors-own [my-patches]

to setup
  clear-all
  create-realtors 10
  [ setxy random-xcor random-ycor
    set size 2
    set shape "circle"
    set my-patches n-of 5 patches in-radius 3
  ]
  ask realtors [ask my-patches [set pcolor [color] of myself ] ]
  reset-ticks
end

You can run it by creating a button for 'setup' or simply typing setup in the command centre.

Upvotes: 2

Related Questions