1

I have a reporter that works fine when I run it but mistakingly when I add a condition to it.

All my turtles have two three dimensional vectors called var_aand var_b. When I run this for my whole world there's no problem:

to-report turtle-bounds [p]
      let p-lower (([item 0 var_a] of p) - ([item 0 var_b] of p))
      let p-upper (([item 0 var_a] of p) + ([item 0 var_b] of p))
      let bounds list p-lower p-upper
      report bounds
end

But when I run it with a condition,

to condition
    let p1 turtles with-max [item 0 var_a]
    turtle-bounds p1
end

I get the following:

  • expected input to be a number but got the list [0.9967359117803329] instead.

Which is referencing a value of var_a, meaning that my restriction somehow makes the [item 0 var_a] of p give a list instead of a number.

Any thoughts?

lomper
  • 379
  • 1
  • 12
  • 2
    `turtle-bounds` is written to take a single agent as its argument, but `with-max` returns an agentset. I'm not sure why running `turtle-bounds` on an agentset gives that particular error, however. What happens if in `to-condition` you use `turtle-bounds one-of p1` to reduce the agentset to an agent? BTW, could p1 have more than one agent in it? – Charles Jul 11 '19 at 14:47
  • Hi @Charles, thanks for your comment. I tried your approach and it does work :). In theory it could be that p1 has more than one agent, but since var_1 is assigned randomly, I'd imagine with-max should only select one. I am not an expert but it may be that `turtles` always marks the agentset as a list even if only one is selected and so `one-of` is mandatory in this case... If you'd like to type the answer feel free to do so, otherwise I'll do it myself. Thanks! – lomper Jul 12 '19 at 09:26

1 Answers1

2

turtle-bounds is written to take a single agent as its argument, but with-max returns an agentset. You can turn the agentset into an agent by using the one-of primitive before giving p1 to turtle-bounds.

to condition
    let p1 turtles with-max [item 0 var_a]
    turtle-bounds one-of p1
end

Alternatively, you could check p in turtle-bounds to see if it is an agentset

if is-agentset? p [set p one-of p]

and make the conversion there, especially if there are other occasions where turtle-bounds might be fed an agentset rather than an agent.

Charles
  • 3,888
  • 11
  • 13