nl.path <- "C:/Program Files/NetLogo 6.0/app"
NLStart(nl.path)
# NLLoadModel(...)
NLCommand("create-turtles 10")
colors <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]")
str(colors)
# or as a list (slightly faster):
colors.list <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]", as.data.frame=FALSE)
str(colors.list)
# or as a list with one list element for each agent
# (very slow!, not recommended especially for large agentsets)
colors.list2 <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]", as.data.frame=FALSE,
agents.by.row=TRUE)
str(colors.list2)
# getting the ends of links is a little bit more tricky, because they store only the
# reference to the turtles and turtles cannot directly be requested.
# A way to go is:
# create some links
NLCommand("ask turtles [ create-links-with n-of 2 other turtles ]")
link.test <- NLGetAgentSet(c("[who] of end1","[who] of end2"),"links")
str(link.test)
Run the code above in your browser using DataLab