Domanda

So I have this current setup

 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'
      ]
    ]
  ]

How can I do this?

È stato utile?

Soluzione

Well, you could ask myself [ set Ac myself ], but this is a bit confusing. (The referent of myself changes every time you enter an ask block, so myself is used twice to refer to two different agents.)

What I would suggest is to assign more explicit variable names to your agents. self/myself are convenient for simple code, but you don't have to use them all the way:

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?
    ]
  ]
]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top