How do I call a parent procedure's variable in netlogo
In netlogo I have a procedure that calls another procedure. How can I go about getting the value
for example, I have two breeds of agents, a hub and a link. A hub has开发者_开发问答 a local variable called 'budget' and I'm trying to modify its value.
hubs-own [
budget
]
to go
ask hub 0 [
do-ivalue
]
end
to do-ivalue
ask links [
;; I'm trying to set the local variable budget of the hub that's calling this link
set self.budget newvalue ;; this is obviously wrong, how can I fix this?
]
end
what you want to do is use is 'myself', it refers to the caller (asker): the one who asked to run the code where the 'myself' is located.
to do-ivalue
ask links [
ask myself [set budget 10] ]
end
The 'self' refers to the agent running the code. It is similar to 'this' in Java.
hmm. not sure why u want to do it this way.. what u can do for now is
ask links[ let new_value new_value_from_link ask hubs[ set budget new_value ] ]
精彩评论