I am starting with LevelSpace extension in NetLogo. I have two version of my code: one does not do what I want, but throws no error: the other does as expected, but only for the first tick, than throws The tick counter has not been started yet. Use RESET-TICKS. error while observer running TICK called by procedure GO called by Button 'go'.
Here are the two snippets of code (note that there are absolutely no error in the netlogo app that this code call).
A) Does not do what I want, but at least run:
to setup
ls:reset
ca
ls:create-interactive-models number_worlds "FlockingModified.nlogo"
ls:ask ls:models [ setup ]
reset-ticks
end
to go
clear-all
ls:ask ls:models [ go ]
let number_centroids [count centroids] ls:of ls:models
let x_centroids [ListXCentroids] ls:of ls:models
let y_centroids [ListYCentroids] ls:of ls:models
let heading_centroids [ListHeadingCentroids] ls:of ls:models
foreach ls:models[
i -> let id_world i
let number_centroid item id_world number_centroids
let xcoords item id_world x_centroids
let ycoords item id_world y_centroids
let headings item id_world heading_centroids
loop [
if number_centroid = 0 [stop]
create-turtles 1 [
set color 15 + 10 * id_world
setxy last xcoords last ycoords
set heading last headings
]
;this is a home made pop, equivalent to java pop
set xcoords but-last xcoords
set ycoords but-last ycoords
set headings but-last headings
set number_centroid number_centroid - 1
]
tick
end
The problem is that it does not change id_world.
I tried a loop version. models is obtained with let models ls:models
.
loop[
if empty? models [stop]
let id_world last models
let number_centroid item id_world number_centroids
let xcoords item id_world x_centroids
let ycoords item id_world y_centroids
let headings item id_world heading_centroids
loop [
if number_centroid = 0 [stop]
create-turtles 1 [
set color 15 + 10 * id_world
last xcoords last ycoords
set heading last headings
]
;this is a home made pop, equivalent to java pop
set xcoords but-last xcoords
set ycoords but-last ycoords
set headings but-last headings
set number_centroid number_centroid - 1
]
;;it never gets to here
set models but-last models
]
Then I have the while version, that throws the error but does what I expected:
let models ls:models
while [not empty? models] [
let id_world last models
let number_centroid item id_world number_centroids
let xcoords item id_world x_centroids
let ycoords item id_world y_centroids
let headings item id_world heading_centroids
while[number_centroid > 0] [
create-turtles 1 [
set color 15 + 10 * id_world
setxy last xcoords last ycoords
set heading last headings
]
;this is a home made pop, equivalent to java pop
set xcoords but-last xcoords
set ycoords but-last ycoords
set headings but-last headings
set number_centroid number_centroid - 1
]
set models but-last models
]
clear-all
also includes clear-ticks
which undoes your reset-ticks
, so calling that in your go
leads to this error. If you want certain things cleared you will have to do so with separate clear commands such as clear-turtles
, clear-patches
, and clear-globals
.