Reputation: 25
I want the first breed (UAV2) to find a circle and turn it black. Then the second breed (supplies) is asked to go to that circle and turn it blue.
I have found that the supply breed doesn't continuously move unless its in either a 'loop' or a 'while'. Both of these work in the sense that the supply goes to the circle at the right time, but the ticks pause, as do the moving uav2s whilst its moving. I want new circles to be found by the uav2s whilst the supply is moving to see the behaviour.
Please help! I may be along the wrong tracks with how to get it to move.
to collide2
set y one-of circles2 in-radius 1 with [color = orange]
set z one-of uav2s in-radius 1
if y != nobody [
ask y [set color black
if color = black[
ask one-of supplies [send-supplies]
]
]]
end
to send-supplies
face y
while [distance y > 1]
[ fd 0.01]
if distance y < 1
[move-to y
ask y [set color blue]
stop ]
Upvotes: 1
Views: 35
Reputation: 17678
Imagine each tick
represents one hour (or whatever duration is sensible for your model). If things happen instantly in the system that is being represented in a model, then a loop
or while
is appropriate. But if it doesn't happen instantly, then you progress through time by incrementing the ticks
counter.
In your case, I suspect that what you want is for the UAV to request supplies, but presumably the supplies should take some time (and therefore multiple ticks) to reach the UAV. I can't tell from your code what y and z are. But you probably want something more like:
supplies-own
[ providing?
provide-target
]
to go
...
send-supplies
...
tick
end
to collide2
...
ask one-of supplies with [not providing?]
[ set providing? true
set provide-target y
]
...
end
to send-supplies
ask supplies with [providing?]
[ face provide-target
ifelse distance provide-target > 1
[ fd 0.01 ] ; this seems like a very small step to me
[ move-to provide-target
ask provide-target [set color blue]
set providing? false
]
]
end
So the idea here is that the supplies breed has a true/false variable for whether it is currently on a supply run (I called this variable 'providing?'). When the collision happens, the UAV asks one of the supplies that is not already on a supply run to start a supply run to provide that UAV. That supplies sets its variable to say it's now on a supply run and also sets the variable saying where the supplies are going.
In your go procedure, every tick all the supplies that are on supply runs get moved (because the call to the procedure that moves them is in the go procedure).
Upvotes: 3