Search code examples
netlogo

error: "a patch cannot access a variable of a turtle without specifying which turtle" in NetLogo


I would like to prevent a turtle from visiting a patch it has visited before. I'm developing the code, but this error appears: error: "a patch cannot access a variable of a turtle without specifying which turtle".

I'm pretty sure it's another syntax error. But, I am not able to find this error. I tried to simplify the code to make it easier for you guys to help me. Any kind of help is welcome.

turtles-own: patchVisited

setup:   set patchVisited (list patch-here)

go:   set patchVisited lput patch-here patchVisited

move:

let availablePatch [neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]] of patch-here
let neighAvailable count availablePatch 

move-to max-one-of availablePatch [resource-value]

Solution

  • Change

    let availablePatch [ neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ] ] of patch-here
    

    to

    let availablePatch neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]
    

    You don't need neighbors of patch-here, that's what neighbors means.

    In general: (1) NetLogo highlights the line with the syntax error. That is useful information for us (and you) so include it in the description of the problem. (2) Make smaller changes in your code - get the smaller change working before moving on. In this case, you could have just one turtle moving around and done something like:

    ask neighbors with [not member? self [patchVisited] of myself] [set pcolor red]
    

    and turned the patches white again afterwards.