How to write values in files for each turtle?

2019-07-27 08:06发布

How can I write values in files for each turtle ? For example, I have 100 turtles and I would like to write data specific to each turtle in 100 files. For the moment, my code writes data for all turtles in one file .txt:

to write-locations-to-file
 file-open "/home/reduan/IBM/outputs.txt"
 ask turtles [ 
  file-print (word who " ; " xcor " ; " ycor " ; " color " ; " [pcolor] of patch-here "\r\n" ) ]
end

Thanks in advance for your help.

标签: netlogo
1条回答
做自己的国王
2楼-- · 2019-07-27 09:06

I'm not sure what it is exactly that you are having trouble with, but you can just open a different file for each turtle. In the example below, I used the who number to generate different file names, but you could use some other method, as long as all file names are unique.

to write-locations-to-files
 ask turtles [ 
   file-open (word "/home/reduan/IBM/outputs-" who ".txt")
   file-print (word who " ; " xcor " ; " ycor " ; " color " ; " [pcolor] of patch-here "\r\n" )
   file-close
 ]
end
查看更多
登录 后发表回答