The tfreporters must report boolean (true or false) values.
For the first tfreporter that reports true, runs the reporter that follows and reports that result. When using only one tfreporter1 you do not need to surround the entire ifelse-value primitive and its blocks in parentheses.
If all tfreporters report false, the result is the value of elsereporter. You may leave out the elsereporter, but if all tfreporters report false then a runtime error will occur.
This can be used when a conditional is needed in the context of a reporter, where commands (such as ifelse) are not allowed.
ask patches [ set pcolor ifelse-value (pxcor > 0) [blue] [red] ] ;; the left half of the world turns red and ;; the right half turns blue show n-values 10 [ifelse-value (? < 5) [0] [1]] => [0 0 0 0 0 1 1 1 1 1] show reduce [ [a b] -> ifelse-value (a > b) [a] [b] ] [1 3 2 5 3 8 3 2 1] => 8
When using more than one tfreporter you must surround the whole ifelse-value primitive and its blocks in parentheses.
ask patches [ let choice random 4 set pcolor (ifelse-value choice = 0 [ red ] choice = 1 [ blue ] choice = 2 [ green ] [ yellow ]) ]
A runtime error can occur if there is no elsereporter.
ask patches [ let x = 2 set pcolor (ifelse-value x = 0 [ red ] x = 1 [ blue ] ; no final else reporter is given, and x is 2 so there will be a runtime error )
Take me to the full NetLogo Dictionary