2

now i have the next problem. Suppose i have a list with diferent numbers for example :

 let mylist [3 7 12 24 32 54 21 19]

And i want to use this list of numbers like the who of turtles. More accurately , i want that only the turtles that his who is equal to of any of the numbers of the list, do a procedure. I tried to applying directly the "with" command like this: ask turtles with [who = mylist] but is not working and i think that the problem is that i am working with a list not a specific value. Any suggestions?

Paul
  • 189
  • 6
  • 1
    In general, it is much better to use agentsets rather than lists of who numbers. (1) Agentsets are much more flexible in creating/amending their memberships. (2) You can directly ask all the members of an agentset to do something with `ask myagentset [ ... ]`. Is there a particular reason you are using who numbers? Can we see the code where you created the list and perhaps we could give you ideas about how to do it with agentsets. – JenB Sep 03 '15 at 06:46
  • 1
    I agree with @JenB. If you really have to convert, you can use `ask turtles with [member? who mylist] [ ... ]` – bergant Sep 03 '15 at 10:27
  • 1
    Agree, using who numbers is nearly always a sign that you're making your life harder than it needs to be. – Seth Tisue Sep 03 '15 at 15:46
  • yeah the primary reason is because, i need that just a certain quantity of turtles do some procedure and others do others procedures but i dont want that the same turtle do all the procedures at the same time so i need a variable that controls exactly which turtles do what thing and what turtle do another thing so, thats why i used who for establish that – Paul Sep 04 '15 at 03:45
  • 1
    That sounds like it would be much easier with agentsets. – Seth Tisue Sep 04 '15 at 18:17

1 Answers1

3

You can use the foreach statement and then ask every turtle with that number. Example

let mylist [1 2 3]
foreach mylist [ ask turtle ?1 [to do some stuff] ]
David Merinos
  • 1,195
  • 1
  • 14
  • 36
  • your code works perfectly I really don't catch very well how to use that "?" thing. Thank you very much – Paul Sep 04 '15 at 03:46
  • It's like some kind of reference parameter or something, I'm not that used to it either, but I like to think of it as absolute/relative references from Excel. Haha! Basically you can use `foreach` for any number of lists. For example `foreach mylist1 myotherlist [ask something ?1 something ?2]` where the `?1` and tells the program to take an element from the first list and `?2` tells the program to take an element from the second list. – David Merinos Sep 04 '15 at 04:26
  • FYI: This won't work for Netlogo 6. `?` was a task and tasks were replaced by Anonymous Procedures. See https://ccl.northwestern.edu/netlogo/docs/transition.html#tasks-replaced-by-anonymous-procedures – Gabriel Fair Oct 03 '18 at 21:45