Reputation: 1
The goal of my model is to demonstrate epizoochory of seeds when hikers step on a plant.
I have two breeds, hikers and plants. Each plant has the variable seed-bank which is a random value up to 500.
What I want to happen, is that when hikers move over a patch where a plant is also at then 80% of the seed bank of the plant is transferred to the hiker (this variable called hiker-seeds). I want this to reflect in real-time meaning that as plants transfer 80% of their seed-bank to the hiker, consequently their seed-bank is reduced by 80%.
I have written the following code:
to go
ask hikers [communicate]
end
to communicate
if any? other plants-here with [seed-bank > 0 ]
[set hiker-seeds (seed-bank of plants in-radius 1) ]
end
I am having difficulty getting the model to take the seed-bank of the plant into account when running 'set hiker-seeds'. I get the error:
"of expected this input to be a reporter block, but got anything else instead".
How to I make the model call upon the seed-bank of the specific plant the hiker interacts with?
Thanks!
Upvotes: 0
Views: 96
Reputation: 2926
Yours is just a syntax problem: of
requires that you place the reporter in square brackets (see here).
In your case, it would be: [seed-bank] of plants in-radius 1
.
This was to solve your current problem. Let me note one more thing: you said you want this to happen "when hikers move over a patch where a plant is". Then know that patches in-radius 1
is not the correct way to do it.
You can verify this by taking an empty environment and running
ask patch 0 0 [ask patches in-radius 1 [set pcolor green]]
in the Command Center. The result is:
which shows that patches in-radius 1
are not just the initial patch of reference.
The primitive patch-here
(see here) is what a turtle needs to use to refer exactly and only to the patch it is standing on.
However, going one step forward: if you're interested in finding other agents that are standing on the same patch as the turtle running the command, you don't need to go through patch-here
; the primitive turtles-here
(see here) exists, which can also be used with specific breeds - which is why Luke in his answer used plants-here
.
Upvotes: 1
Reputation: 10301
One way to do this is to create a temporary variable within the procedure where the exchange occurs to track the amount that is to be transferred, then update the values of both hiker and plants correspondingly. For example (more details in comments):
breed [ plants plant ]
breed [ hikers hiker ]
plants-own [ seed-bank ]
hikers-own [ hiker-seed ]
to setup
ca
ask n-of 20 patches [
sprout-plants 1 [
set seed-bank random 500
set shape "plant"
]
]
ask n-of 10 patches [
sprout-hikers 1 [
set shape "person"
]
]
reset-ticks
end
to go
ask hikers [
rt random 40 - 20
fd 1
; Check for plants on the current patch
if any? plants-here with [ seed-bank > 0 ] [
print "I'm taking some seeds!"
; Get each plant that is here to:
ask plants-here [
; Calculate the seed-bank amount to transfer
let seed-exchange round ( seed-bank * 0.8 )
; Update the hiker-seed of myself (the current hiker)
ask myself [
set hiker-seed hiker-seed + seed-exchange
]
; Update the plant's seed bank
set seed-bank seed-bank - seed-exchange
]
print ( word "I now have " hiker-seed " seeds.")
]
]
tick
end
Upvotes: 1