My model has 4 breeds:
breed [ offices office ]
breed [ service-desks service-desk ]
breed [ employees employee ]
breed [ citizens citizen ]
offices-own [ money ]
employees-own [ money-held ]
citizens-own [ money-received ]
In my setup procedure I ask the offices
and service-desks
breeds so that I can use a unique shape:
create-offices 1
ask offices [
set shape "building institution"
set size 4
set color yellow
set money num-of-money ]
ask patch 0 8 [
sprout 1 [
set breed service-desks
set shape "building institution"
set color pink
set size 3 ]
offices
has an attribute money
.
What I am trying to accomplish is that an employee
will go to the office
and collect money
. Then will travel to a service-desk
where they will meet with a citizen
breed to handover they money they hold.
What I've tried is:
to employee-give-money
ask employees [
if any? citizens in-radius 1 [
set money-held money-held - 1
]
]
ask citizens [
set money-received money-received + 1
set color orange
]
Basic transaction of resources is pretty simple to code with addition and subtraction. Below I have a sample code for how it works.
You might want to build in some safeties in take-money
so that a turtle can't have negative money.
turtles-own [money]
to setup
ca
crt 5 [
setxy random-xcor random-ycor
set money random 1000
]
end
to test
ask turtle 0 [take-money turtle 1 500]
end
to take-money [ from-who amount ]
ask from-who [ set money money - amount ]
set money money + amount
end
This snippet of code is to visualise the money all turtles have in order of their who. I used it in a monitor on the interface to make sure everything was happening as intended.
to-report turtle-assets
let new-list []
foreach sort turtles [the-turtle -> ask the-turtle [set new-list lput money new-list]]
report new-list
end
Now that the basics are out of the way, let's look at your case.
if turtle shape = ...
doesn't work because there is no such thing as turtle shape
. The variable is just shape
. But anyway, you are already working with breeds, so there is no need to bother with shapes at all. You can use the <breeds>-here
reporter to let agents interact with other local agents. In your case the employees
want to interact with the offices-here
.
to collect-paycheck
ask employees [
if any? offices-here [
take-money one-of offices-here 500 ;or however much you want them to take
]
]
end
This code will let each employee take 500 money from a random office on their own patch (I assume only 1 office per patch though) each time it is called.