Reputation: 449
I have a question that I don't know how to resolve. I have code that exports the following information to a .csv file:
However, if I have a line of code that the bee dies when it reaches a certain amount of resource (for example when it reaches an amount > = a 2 resource the turtle dies. To simplify the code I put here that upon reaching the tick >=2 the turtle dies). The issue is that at tick 2 the turtle dies and the pxcor and pycor value of the last tick (tick 2) is not exported. So, just like when inspecting the turtle, the turtle dies and we don't see the last updated tick information.
Does anyone know how I can get this information?
If I haven't been able to express myself properly. I can rewrite my question or try to rewrite the simplified code.
Thanks in advance
to setup
clear-all
reset-ticks
resize-world 0 3 0 3
ask patches [ sprout 1 [ setup-turtles ] ]
let pcolors [ ]
set pcolors [ 1 10 ]
ask patches [ set pcolor item (random 2) pcolors ]
end
to setup-turtles
set size 0.5
pen-down
end
to go
move
output
tick
end
to move
ask turtles [
rt random 360
fd 1
if ticks >= 2 [ die ]
]
end
to output
file-open "test.csv"
foreach sort turtles
[
t ->
ask t
[
file-print ( word self " , " pxcor " , " pycor " , " ticks )
]
]
file-print "" ;; blank line
file-close
end
Upvotes: 0
Views: 87
Reputation: 2926
The answer to this question was already included in this answer you previously received.
You have to arrange commands in a way that asks turtles to execute output
before die
.
For example
if ticks >= 2 [output die]
Or
to go
move
tick
end
to move
ask turtles [
rt random 360
fd 1
output
it ticks >= 2 [die]
]
end
Or any other arrangement where you ask your turtles to do things before you kill them, because they cannot do things once they are dead.
Upvotes: 2