Reputation: 339
When one variable of a patch reaches a certain value (e.g. age = 75
), I redirect the patch to another procedure (called retirement
) where I want to select all the patches that share the same value of the variable Farm_ID
so the procedure is applied to all the patches.
I'm looking for a command which mean "the same as", I also considered to use the to-report
and report
procedure to report the pxcor
and pycor
of the original patch and then ask the other patches with the same ID_Farm as the patch pxcor pycor
But I feel like I'm missing something in the essence of using Netlogo (I'm a newbie).
to start-simulation
reset-timer
tick-advance 70
;; increase the farmer's age
ask patches with [seed = 1] [set age age + 1]
ask patches [
if age = 75 [ retirement ]
]
;; other stuffs
end
to retirement
ask patches with [ ID_Farm = ???]
;; procedure to change the variable ID_Farm depending on the closest patches with a different ID_Farm
end
Upvotes: 0
Views: 272
Reputation: 2926
You need myself
(see here), and more specifically you need to use variable = [variable] of myself
.
See a minimal and reproducible example below:
to setup
clear-all
ask patches [
ifelse (pxcor > 0)
[set pcolor lime]
[set pcolor orange]
]
end
to go
ask one-of patches [
type "I am the chosen patch. My color is " type (ifelse-value (pcolor = 25) ["orange"] (pcolor = 65) ["lime"] ["cyan"]) print ". I and all patches having my same color will become cyan."
operate-on-patches-with-my-same-color
]
end
to operate-on-patches-with-my-same-color
ask patches with [pcolor = [pcolor] of myself] [
set pcolor cyan
]
end
When you check the myself
entry in the NetLogo Dictionary, note the difference between self
and myself
. At the beginning it may be confusing, but as you get more and more used with how NetLogo works it will become clear.
Upvotes: 2