I can't figure out why this code is executing multiple times per "highlanders with [ cacao-grower = true ]". It is cumulatively adding up the values for "exchange-value-wealth" for ALL such agents, once per agent. So when there is only one such agent, it is correct, according to what I want the code to do. But when there are two such agents, it does it two times for each agent, instead of the two times I'd expect, and also incorrectly adds results from the first tick AGAIN. And when there are three such agents, it does it three times more and again adds the former cumulative sum incorrectly.
to harvest-cacao
ask highlanders with [ cacao-grower = true ] [
let owner-id who
let max-res-of-owned-patches [ max-resource-here ] of patches with [ owner = owner-id ]
show word "max-resource-here values of each patch owned: " max-res-of-owned-patches
let cacao-values [] ; an empty list, to start, of the cacao crop values
foreach max-res-of-owned-patches [ x -> set cacao-values lput (x * 2) cacao-values ] ; sets the cacao crop values list as product of max-resource-here * 2, just for simplicity / testing.
show word "cacao crop values: " cacao-values
let cacao-total sum cacao-values ; total value of all cacao crops owned by each grower
set exchange-value-wealth exchange-value-wealth + cacao-total
print word "exchange-value-wealth: " exchange-value-wealth
]
end
The full model code is attached in case that's handy. It is slightly different than the above, for simplicity.
Thanks in advance for any help!
Lee