i have problems converting old NetLogo Code to work with NetLogo 6.0.1
The line I am having trouble with is the following:
set recv turtle (read-from-string ?)
I know that ? has been changed to ->. But i can't figure out, how this line works.
The whole code is:
to send [msg]
let recipients get-receivers msg
let recv 0
foreach recipients [
set recv turtle (read-from-string ?)
if recv != nobody [without-interruption [ask recv [receive msg]]] ;; read-from-string is required to convert the string to number
]
end
The ?
representing each element of recipients
is now replaced by a local variable declared within the foreach
brackets. Here, I've declared a variable recip
, but it can be anything you want.
to send [msg]
let recipients get-receivers msg
let recv 0
foreach recipients [recip ->
set recv turtle (read-from-string recip)
if recv != nobody [without-interruption [ask recv [receive msg]]] ;; read-from-string is required to convert the string to number
]
end
Two nice things about this: you can "name" the question mark, making it easier to remember what it stands for, and, if you are iterating over more than one list, you can declare more than one variable, one for each list.