Reputation: 511
I'm building interactions for a prey-predator model.
I have a prey that changes color based on the state that it is currently in. The state that I'm working on is "hiding", in which the prey is yellow. I have a predator working to evaluate if it can chase a prey, I'm attempting to do this by evaluating the color of the prey but it doesn't seem to be working.
to chase
let target min-one-of prey [distance myself]
output-print target
ifelse target != yellow
[
output-print "chase"
]
[
output-print "ignore"
]
end
When I run the model the predator constantly prints "chase" - regardless of whether the prey is "hiding" or not.
Here is the hiding function.
to hiding
set color yellow
set energy (energy - 1)
if (count predators = 0)
[
output-print "safe"
]
end
Any help would be appreciated.
Upvotes: 4
Views: 97
Reputation: 2096
to access the color (or any other variable of an agent) you surround the variable name in brackets and use "of" thus
[color] of target
in context of your code it would look like this
to chase
let target nearest-of prey
output-print target
ifelse [color] of target != yellow
[
output-print "chase"
]
[
output-print "ignore"
]
end
it takes some time to get used to as it is quite different than the object.variable form used by "C" style languages.
Upvotes: 2