Load in data for turtles in Netlogo: loop seems to stop

37 Views Asked by At

I'm trying to load data from R to Netlogo. I always get the error

Cannot move turtle beyond the worlds edge.
error while turtle 8 running SET
called by procedure LOAD-DATA
called by procedure SETUP
called by Button 'Setup'

I defined the world edge


      let minworldx r:get "min(dataTurtle$bcx)"
      let maxworldx r:get "max(dataTurtle$bcx)"
      letminworldy r:get "min(dataTurtle$bcy)"
      let maxworldy r:get "max(dataTurtle$bcy)"
      resize-world minworldx maxworldx minworldy maxworldy

The turtles are defined as follows


    set dataTurt r:get "dataTurtle" ; transfers data to Netlogo
     print dataTurt  ; just to test
      ask turtles  ; reads in data to the variables
      [ set color 14
        set heading 1
        set xcor item who Item 1 dataTurt
        set ycor item who Item 2 dataTurt
        set label item who Item 0 dataTurt
        set P_FertSpace 2000  ; just a value test value
        
        ]

How can I ensure that all turtles that I create get the assinged data?

1

There are 1 best solutions below

0
On BEST ANSWER

The loop is stopping because there's an error. The error message tells you that the error is because you are trying to put a turtle in a place that doesn't exist.

Does this fix it?

  let minworldx floor r:get "min(dataTurtle$bcx)" - 1
  let maxworldx ceiling r:get "max(dataTurtle$bcx)" + 1
  let minworldy floor r:get "min(dataTurtle$bcy)" - 1
  let maxworldy ceiling r:get "max(dataTurtle$bcy)" + 1
  resize-world minworldx maxworldx minworldy maxworldy

I have used floor and ceiling to round down and up respectively, and then added or subtracted 1 for extra safety. This should make sure the turtles don't get positioned outside the world boundaries.