Reputation: 449
I have a very basic question on NetLogo. However, I don't know how to solve it. I would like to run an equation and have the value of that equation used by all turtles. I made the following code:
to equation
ask turtles [
set 10 ^ ( - 0.1 + 2.0 * log Size 10 ) * 1000
]
end
Can someone help me?
Thanks
Upvotes: 0
Views: 163
Reputation: 1181
If the turtles all need the same value, the calculation could be done just once in order to improve runtime. Additionally consider saving that value as a global variable.
globals [the-answer]
to equation
set the-answer 10 ^ ( - 0.1 + 2.0 * log Size 10 ) * 1000
end
Upvotes: 0
Reputation: 17678
you need to assign the answer to the equation to some variable. For example (not tested):
turtles-own [the-answer]
to equation
ask turtles [
set the-answer 10 ^ ( - 0.1 + 2.0 * log Size 10 ) * 1000
]
end
The turtles-own
statement sets up an attribute for each turtle so that each turtle has its own value of that attribute (and therefore different turtles can have different values because their size varies)
Upvotes: 1