In my program, each turtle (namely glucose and bacteria) has their own variable called mass. The setup procedure states that the initial mass of glucose and the bacteria is 1 mmol. The to-go procedure says that the glucose will be hydrolyzed and divided. Thus the glucose_mass will be different to the initial 1 mmol. The to-go procedure for the bacteria says that when the bacteria eats one glucose then the mass of the bacteria will grow from the initial 1 mmol plus the mass of the glucose (stochastic number determined in the to divide_hydrolyzed_glucose procedure) that it consumed times a fixed number (i.e. 0.3). I tried to use the command "of myself" to include the variable of another turtle into the bacteria turtle. However, it gives me an error saying that "OF expected this input to be a reporter block, but got a variable or anything instead".
Any comments or suggestions on this issue?
Breed [glucose a-glucose];; Food
Breed [bacteria a-bacteria] ;; Predator
glucose-own [glucose_mass]
Bacteria-own [Bacteria_mass]
to setup
;;;GLUCOSE;;;
set-default-shape glucose "circle"
Create-glucose (8) ;; Create the glucose available in mmol/d,
[set glucose_mass (1) ;; in mmol
]
;;; BACTERIA;;;
Create-Bacteria (8) ;; Create the clostridiales in mmol
[set Batceria_mass (1)
]
end
to go
ask glucose
[
Hydrolyse_glucose
Divide_hydrolyzed_glucose
]
ask Bacteria
[ Bacteria_eat_glucose]
to hydrolyse_glucose
if (glucose_mass < 200) [
set glucose_mass ((glucose_mass * 0.025 + random-float 32.975) / 24)
]
end
to divide_hydrolyzed_glucose
if (glucose_mass > 1)
[
set glucose_mass (glucose_mass / 2)
hatch 1
]
end
to Bacteria_eat_glucose
let prey one-of glucose-here
if prey != nobody
[ask prey [die]
set Bacteria_mass (Bacteria_mass + ((glucose_mass of myself) * 0.3))
]
end
The error message might be seem hard to interpret at first, but it's telling you exactly what is wrong: the of
primitive wanted a reporter block, but you gave it a variable instead.
So you would need:
[ glucose_mass ] of myself
The square brackets tell NetLogo that glucose_mass
should be wrapped into a "reporter block", that is something that can be run in a different context (in this case, [ glucose_mass ]
would be run in the context of myself
.)
Looking more closely at code, however, it seems that myself
is not what you need. The myself
primitive is used to refer to the agent from the "outer" context... when there is one, which is not the case here.
I would suggest you restructure your Bacteria_eat_glucose
procedure like this:
to Bacteria_eat_glucose
let prey one-of glucose-here
if prey != nobody [
set Bacteria_mass Bacteria_mass + [ glucose_mass * 0.3 ] of prey
ask prey [ die ]
]
end
A few things to notice:
myself
has been replaced by prey
;* 0.3
inside the reporter block because I find it easier to read, but [ glucose_mass ] of prey * 0.3
would have been just as fine;set Bacteria_mass ...
line needs to come before the prey dies, otherwise the glucose_mass
of the prey would not be accessible anymore.