How to use the primitive "patch-right-and-ahead" when the world wrapping is disabled in the model settings?

StackOverflow https://stackoverflow.com/questions/22967983

  •  30-06-2023
  •  | 
  •  

Pregunta

I have a problem with the primitive "patch-right-and-ahead". When the world wrapping is disabled in the model settings, I obtain the following error message:

OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead.

when I do :

if [pcolor] of patch-here = brown [
 if [pcolor] of (patch-right-and-ahead 90 1) = brown [
  move-to patch-right-and-ahead 90 1 ] ]

Thanks in advance for your help.

¿Fue útil?

Solución

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
  ]
]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top