NetLogo creates turtles from list values

I have successfully loaded the values ​​from a tab-delimited data file (.txt) into a list box, with xcor, ycor and color values ​​for each of the 10 turtles. I read the data using:

file-open "File Input Load Turtles.txt"
set turtle-data sentence turtle-data (list (list file-read file-read file-read))

      

I am now trying to create 10 new turtles based on the values ​​in the new list. I tried the following syntax (among many unsuccessful attempts):

foreach turtle-data crt set xcor first ? set ycor item 1 ? set color last ? 

      

Firstly? in the foreach command, NetLogo reports the error "This special variable is not defined here."

Can anyone tell me the correct syntax to iterate over a list of 10 subscriptions to do the xcor set, set ycor, and set the color commands in the foreach loop to create 10 turtles?

Many thanks!

+3


source to share


1 answer


It's just a syntactic problem. NetLogo understands foreach turtle-data crt

as a value foreach turtle-data [ crt ? ]

and then the rest are parsed as separate commands hence you see an error.

Do you want to:



foreach turtle-data [
  crt 1 [
    set ...
  ]
]

      

with square brackets to delimit where the body of the loop starts and ends. Please note that you must provide a number crt

.

+3


source







All Articles