0

I am creating a netlogo program where patches own two variables, one is "cheiro" and the other is "tempo".

The turtles are walking around the patches and before moving they check manually each patch around if the patch has cheiro = 1. This is the code I have and it gives me an error.

    ask patch-ahead 1[
        if cheiro = 0 [set m1 patch-ahead 1]
        ]
]

The error given is " You cant use PATCH-AHEAD in a patch-context, because PATCH-AHEAD is turtle-only.

I also tried

if patch-ahead 1 with [cheiro = 0][set m1 patch-ahead 1]

But was given error saying "WITH expected this inpput to be an agentset, but got a number instead."

1 Answers1

2

When you say ask patch-ahead..., you are asking the patch to do something rather than the turtle. Obviously it makes no sense to ask a patch whether the patch ahead has some value since patches don't move and therefore don't have a reference direction. You probably want something like:

if ([cheiro] of patch-ahead 1) = 0 [...]

I have included brackets so you can see what the code is doing, but they aren't necessary for it to run. This looks at the next patch (from the perspective of whichever turtle is asking) and checks the value of the variable 'cheiro'. If that value is 0, then the code in the [ ] is run.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thanks ! I just came back to say i managed to solve it ! I did it like ```if [cheiro = 0] of patch-ahead 1[set m1 patch-ahead 1] ``` – Mauro Abrantes Nov 07 '20 at 13:42