I'm getting this
error,
“Nothing named BEST-AMOUNT has been defined”, but I can't figure out why. I've gone over and over this and it seems like it IS defined.
I'm attempting to build on code that enables turtles to ascertain in which direction to turn, to move one patch ahead and find the "most resources". This original code does NOT have the same problem with the error above. That code is as follows:
to turn-towards-resource
set heading 0
let best-direction [0]
let best-amount resource-ahead ; see "to-report resource-ahead", procedure.
set heading 90
if (resource-ahead = best-amount) [set best-direction lput 90 best-direction]
if (resource-ahead > best-amount) [set best-direction [90] set best-amount resource-ahead]
set heading 180
if (resource-ahead = best-amount) [set best-direction lput 180 best-direction]
if (resource-ahead > best-amount) [set best-direction [180] set best-amount resource-ahead]
set heading 270
if (resource-ahead = best-amount) [set best-direction lput 270 best-direction]
if (resource-ahead > best-amount) [set best-direction [270] set best-amount resource-ahead]
ifelse best-amount > (norm-min-resource * max-resource-here) [
set heading one-of best-direction
][
set heading one-of [0 90 180 270]
]
end
What I'm trying to add to the above is just that the turtles will avoid patches with a patches-own boolean variable [cacao-crop = true]. The re-written procedure, which DOES cause the error, is as follows:
to turn-towards-resource
set heading 0
ifelse [ cacao-crop = false ] of patch-ahead 1 [ ; if the patch ahead is not an owned cacao farm, let the first direction tested be the "best direction" so far.
let best-direction [0]
let best-amount resource-ahead
]
; On the other hand, if it is an owned cacao farm don't go there...
[
let best-amount 0 ; if it's owned cacao farm, consider the resources for non-cacao-growers there to be zero
let best-direction [0]
] ; and the direction of heading can just stay the same, won't matter b/c in the end, if it's heading in a direction of a cacao farm b/c that's all there is then I'll code it to jump to random non-cacao patch.
set heading 90
ifelse [ cacao-crop = false ] of patch-ahead 1 [
if (resource-ahead = best-amount) [set best-direction lput 90 best-direction]
if (resource-ahead > best-amount) [set best-direction [90] set best-amount resource-ahead]
]
[
let best-amount 0
let best-direction [0]
]
set heading 180
ifelse [ cacao-crop = false ] of patch-ahead 1 [
if (resource-ahead = best-amount) [set best-direction lput 180 best-direction]
if (resource-ahead > best-amount) [set best-direction [180] set best-amount resource-ahead]
]
[
let best-amount 0
let best-direction [0] ]
set heading 270
ifelse [ cacao-crop = false ] of patch-ahead 1 [
if (resource-ahead = best-amount) [set best-direction lput 270 best-direction]
if (resource-ahead > best-amount) [set best-direction [270] set best-amount resource-ahead]
]
[
let best-amount 0 ; if patches in every direction are owned, best-amount = 0 and...
let best-direction [0] ] ; ...best-direction = 0 ...I think this won't matter that much.
; the code should help avoid patches with [ cacao-crop = true ], but if they are all owned, a direction will be chosen at random. Then in "to go" I'll address this, making it jump to non-cacao patch.
ifelse best-amount > (norm-min-resource * max-resource-here) [
set heading one-of best-direction
][
set heading one-of [0 90 180 270]
]
end
I'll attach the entire model's code, in case that is handy.