Search code examples
netlogopatchidentifier

Setting specific patch identifier


I want to have specific 'who' (labels) of the patches.I have attached a picture for it. How can I set it? Is it setting manual 'who' of patch numbers? or Is there any other way of doing it?

Thanks

picture for patch identifiers


Solution

  • If you don't care about the specific "spiral" sequence in your example, you can use a variant of Luck's solution that takes advantage of NetLogo's default patch sort order:

    patches-own [ id ]
    
    to setup
      clear-all
      (foreach (sort patches) (range count patches) [ [p n] ->
        ask p [ set id n ]
      ])
      ask patches [ set plabel id ]
    end
    

    Or you could use a slightly different sort order specified with sort-by.

    That being said, I don't know what your requirements are, but I would question the idea of having a specific id for patches. Most things in NetLogo can be done without ever refering to an agent's id. The who number itself is a relic of very old NetLogo versions and should almost never be used in modern code.

    If you want to refer to a specific patch, refer to it by its coordinates, for example: patch -2 4.

    If you want to store a patch for future reference, store a reference to the patch itself, not some kind of id. For example: ask turtles [ set my-patch one-of patches ].