Reputation: 69
I'm trying to select the closest free carrier to the cutter and send them to retrieve a metal sheet from delivery for the cutter to cut. This is the relevant code:
globals[
metal-sheets
cutter-closest-free-carrier]
breed[carriers carrier]`
to cut
let free-carriers carriers with [laden = false]
let cutter patches with [machine-type = "cutter"]
let delivery patches with [area = "delivery"]
ask cutter [
if status = "import" [
set cutter-closest-free-carrier min-one-of free-carriers[distance myself]] ]
if any? cutter-closest-free-carrier[
ask cutter-closest-free-carrier [
face delivery
fd 0.01
set metal-sheets cars-here
if any? metal-sheets [
create-link-to one-of metal-sheets [tie]
face cutter
fd 0.01
ask cutter[set status "pending"]]
]
]
end
The error message I get is:
"ANY? expected input to be an agentset but got the number 0 instead."
How can I make this function in the intended way?
Upvotes: 2
Views: 253
Reputation: 4168
I'm assuming that the error is with this:
if any? cutter-closest-free-carrier[
As a global variable, cutter-closest-free-carrier
is initialized by NetLogo to zero. If in
ask cutter [
if status = "import" [
set cutter-closest-free-carrier min-one-of free-carriers[distance myself]] ]
status
is not equal to "import", then cutter-closest-free-carrier
will still be zero when you apply any?
to it. Thus the error. There is another problem too - any?
should be applied to agentsets and even if status = "import"
, cutter-closest-free-carrier
will be a single agent as a result of min-one-of
, not an agentset.
So, first initialize cutter-closest-free-carrier
to nobody
, either in your setup or at the beginning of to cut
. Then change the test for there being a cutter-closest-free-carrier
to
if cutter-closest-free-carrier != nobody [
I think that should do it.
Hope this helps, Charles
Upvotes: 2