如何在文件中为每只海龟写入值? [英] How to write values in files for each turtle?
本文介绍了如何在文件中为每只海龟写入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 "
" ) ]
end
提前感谢您的帮助。
推荐答案
我不确定您到底遇到了什么问题,但您可以为每个海龟打开不同的文件。在下面的示例中,我使用who
号来生成不同的文件名,但您也可以使用其他方法,只要所有文件名都是唯一的。
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 "
" )
file-close
]
end
这篇关于如何在文件中为每只海龟写入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文