如何在 netlogo 中调用父过程的变量
在 netlogo 中,我有一个调用另一个过程的过程。我怎样才能获得价值
,例如,我有两种代理,一个集线器和一个链接。集线器有一个名为“预算”的局部变量,我正在尝试修改它的值。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你要做的是使用'myself',它指的是调用者(asker):要求运行'myself'所在代码的人。
“自身”是指运行代码的代理。它类似于 Java 中的“this”。
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.
The 'self' refers to the agent running the code. It is similar to 'this' in Java.
唔。
不知道为什么你想这样做..
你现在能做的就是
询问链接[
让 new_value new_value_from_link
询问集线器[
设置预算 new_value
]
]
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
]
]