Question

i have the following breed in my model.

  ants-own  
 [
  hops
  distance-gone
  distance-to-go
  target-node
  current-node
  ]

the current node gets updated and stores the link of new node ( i want to store the different values of current-node in a list ).

i have the following code

     set b lput current-node b

where this code iterates through a procedure n stores the node number using this command. But i am getting the following error

      LPUT expected input to be a list but got the turtle instead

how to store agents in a list?

Was it helpful?

Solution

Apparently your variable b contains a turtle, not a list. Did you initialize b to contain an empty list?

lput won't create a list from nothing. It can only add an item to an existing list.

Here's some code showing that lput works just fine for adding turtles to a list, as long as you have a list (perhaps empty) to begin with:

to test
  crt 10
  let b []
  repeat 5 [
    set b lput (one-of turtles) b
  ]
  print b
end

when I run this in the Command Center, I see:

observer> test
[(turtle 3) (turtle 8) (turtle 8) (turtle 1) (turtle 3)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top