When a primitive that normally returns an agent can't find an appropriate agent to return, it will return nobody
. Here, there is no patch that's right and ahead of the current agent (er, since the angle is 90, I guess just right of). Thus, it's returning nobody
. You need to check to make sure it's not nobody
before using of
on it:
if [pcolor] of patch-here = brown [
let target-patch patch-right-and-ahead 90 1
if target-patch != nobody and [pcolor] of target-patch = brown [
move-to target-patch
]
]