0

所以我有这个当前的设置

 ask turtles [                               ;i want this turtle (myself)
    ask other turtles [                      ;to ask other turtle, one by one (self)
      if Smin < Sim myself self [            ;to run a function wherein 
       ifelse Sim myself self < Smax         ;if Smin < Sim myself self < Smax
       [ ;if block ]                         ;self will be assigned to the variable
       [ ;else block ]                       ;of myself called 'Ac'
      ]
    ]
  ]

我怎样才能做到这一点?

4

1 回答 1

3

好吧,你可以ask myself [ set Ac myself ],但这有点令人困惑。(myself每次进入一个ask块时,所指的对象都会改变,所以myself用两次来指代两个不同的代理。)

我的建议是为您的代理分配更明确的变量名称。self/myself对于简单的代码很方便,但你不必一直使用它们:

ask turtles [              
  let t1 self
  ask other turtles [      
    let t2 self
    if Smin < Sim t1 t2 [  
      ifelse Sim t1 t2 < Smax   
        [ ask t1 [ set Ac t2 ] ]
        [ ] ; do something else?
    ]
  ]
]
于 2013-09-09T12:56:09.880 回答