Search code examples
netlogocoordinate

Set label at specific coordinates in netlogo


how can I set the label at specific coordinates in netlogo. I have tried following methods

ask people
    [setxy -16 15 ;Defining Positions  
     set label (word (WORD "This is: John " ))   
     set label-color white]  

; people is my turtle

But setxy moves both my turtle and label to (-16,15). I just want to move the label to these coordinates. The turtle should remain where it was. Any help will be appreciated since I am new to Netlogo and am trying to learn this language as much as I can.Thank you so much


Solution

  • The label is attached to the turtle. It always moves with it.

    If you want a label at a fixed position, however, you can use a patch label: plabel. For example:

    ask patch -16 15 [
      set plabel "This is: John"
      set plabel-color white
    ]
    

    Another possibility, to get a bit more flexibility, is to create a dummy breed of turtles and use them exclusively for labels:

    breed [ signs sign ]
    
    to setup
      clear-all
      create-signs 1 [
        setxy -9.5 13.5
        set size 0 ; hide the turtle, but not the label
        set label "This is: John"
        set label-color white
      ]
    end
    

    This way, you can use more precise coordinates and move the labels around if needed.