如何在 netlogo 中调用父过程的变量

发布于 2024-10-16 19:57:00 字数 394 浏览 5 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉风有信 2024-10-23 19:57:00

你要做的是使用'myself',它指的是调用者(asker):要求运行'myself'所在代码的人。

to do-ivalue   
  ask links [
    ask myself [set budget 10]   ] 
end

“自身”是指运行代码的代理。它类似于 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.

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.

水波映月 2024-10-23 19:57:00

唔。
不知道为什么你想这样做..
你现在能做的就是

询问链接[
让 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
]
]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文