user399466
user399466

Reputation: 117

How to write a basic NetLogo `if` statement for patch colors

I am trying to apply the following condition:

if ( the color of patch -2 -1 is red ) [ some commands ]

Could someone please tell me how to write this in NetLogo?

Upvotes: 1

Views: 2609

Answers (2)

Kev
Kev

Reputation: 313

You could do it with a with to get the agentset like Jose M Vidal has suggested.

1) Using AgentSet

ask patches with [pcolor = black]  [ commands here ]

2) If you want to use an if condition specifically, write it as such:

ask patches [ if [pcolor] of self = black  [ commands here ] ]

Upvotes: 1

Jose M Vidal
Jose M Vidal

Reputation: 9142

If you mean the patch at coordinates (-2 1) then its:

ask (patch -2 1) with [pcolor = red] [commands]

or

ask (patch -2 1) [ if (pcolor = red) [commands]]

Upvotes: 2

Related Questions