代码之家  ›  专栏  ›  技术社区  ›  user2359494

观察员上下文中补丁的NetLogo映射变量

  •  0
  • user2359494  · 技术社区  · 7 年前

    我试图按照生成补丁的列表的相同顺序映射补丁变量(请参见下面的代码)。然而,我得到了一个“观察员运行SET test2时出错”,因为它不能在观察员上下文中运行。我不理解这一点,因为这似乎是一个简单的过程。

    globals [test test2]
    patches-own [wealth]
    to setup
      ca
    ask patches
      [set wealth random 100]
    end
    to go
      set test [self] of patches
      show test
      set test2 map [wealth] test
      show test2
    end
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Alan    7 年前

    你可以改变 set test2 map [wealth] test set test2 map [x -> [wealth] of x] test . 然而,每当您使用代理列表而不是代理集时,您应该询问这是否真的有必要。