【问题标题】:NetLogo: Can't "stop" forever button from another procedure?NetLogo:不能从另一个程序“停止”永远按钮?
【发布时间】:2019-01-06 06:54:31
【问题描述】:

我在下面简化了我的问题。当没有机器人时,我想停止执行永久按钮“go”,并且我想从另一个过程(在本例中为“test”)调用它,如下所示:

to go
 test
end

to test
  if not any? robots [ stop ]
end

这样做的原因是我想在机器人死亡的地方调用停止,以便我可以发送适当的用户消息。

【问题讨论】:

    标签: button netlogo execution forever


    【解决方案1】:

    遗憾的是,您必须重新组织您的代码,以便在您的 go 中调用 if not any? robots [ stop ] 才能使以下内容为真:

    查看文档:

    也可以从代码中停止永久按钮。如果永远按钮 直接调用一个过程,然后当该过程停止时,按钮 停止。 (在乌龟或补丁永远按钮中,按钮不会停止 直到每只乌龟或补丁停止——单个乌龟或补丁不会 有能力停止整个按钮。)

    参考:http://ccl.northwestern.edu/netlogo/docs/programming.html#buttons

    stop 该代理立即退出封闭过程,询问, 或类似询问的构造(例如 crt、hatch、sprout)。只有封闭的 过程或构造停止,而不是代理的所有执行。

    参考:http://ccl.northwestern.edu/netlogo/docs/dict/stop.html

    我很想不发布的另一种 hacky 解决方案可能是执行以下操作,您提出一个错误然后停止。

    to go
       carefully[test][error-message stop]
    end
    to test
       if not any? robots [ error "no more robots!" ]
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 2015-12-06
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多