Reputation: 71
So, I have a list of lists. Kinda like that:
set plist [(list patch-at 0 0 100) (list patch-at 20 20 70) ...]
So the resulting list is a list of pairs "patch, number". What I need to do is to do a foreach on that plist, and for each list in that list, I want to decrement the number, lets say in "go" function. So every tick, I want the number to be 1 less.
I failed to think of a way to get to that number. There is a code I have in go, ask turtles [ ]:
foreach listp [
set item 1 ??? item 1 ??? - 1
if item 1 ??? <= 0 [remove ??? listp]
]
Where ??? is for the name of list i don't know (the nested lists). Obviously what I am trying to do is remove the patch from the list after 100 ticks.
Is there a way to reference those lists, or a way to somehow call "set item 1" without specifying the name of the list?
Thanks in advance! :)
Upvotes: 1
Views: 559
Reputation: 9610
turtles-own [plist]
to setup ;;create an initialize some turtles
ask n-of 10 patches [
sprout 1 [
set plist (list (list patch-at 0 0 100) (list patch-at 20 20 70))
]
]
end
to go ;;update the `plist` of each turtles
ask turtles [
set plist map [list first ? (last ? - 1)] plist
set plist filter [last ? > 0] plist
]
end
Upvotes: 2