Mick McWilliams
Mick McWilliams

Reputation: 43

NetLogo create turtles from list values

I have successfully loaded values from a tab-delimitted (.txt) data file into a List, with xcor, ycor & color values for each of 10 turtles. I read in 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'm now trying to create 10 new turtles based on the values in the new List. I tried the following syntax (among many other unsuccessful attempts):

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

At the first ? in the foreach command NetLogo reports the error "This special variable isn't defined here."

Can anyone please tell me the correct syntax for iteratively referencing the list of 10 sub-lists to execute the set xcor, set ycor and set color commands in the foreach loop to create the 10 turtles?

Thanks very much!

Upvotes: 4

Views: 990

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

This is just a syntax issue. NetLogo understands foreach turtle-data crt as meaning foreach turtle-data [ crt ? ], and then the rest is parsed as separate commands, hence the error you're seeing.

You want:

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

with the square brackets to delimit where the body of the loop begins and ends. Note that you must supply a number to crt.

Upvotes: 3

Related Questions