AKarr
AKarr

Reputation: 183

Why am i getting the expected a true/false here rather than an a list or block here?

   I have the code:

 if [pcolor] of patch-here = grey and  [pcolor] n-of 2 neighbors4 =       grey   [set  X X + 1 set  agentset-number = N] 

This seemed to produce no error before hand, I am curious as to what is incorrect within this snippet of code and how it can be corrected.

Upvotes: 1

Views: 1173

Answers (1)

Arthur Hjorth
Arthur Hjorth

Reputation: 889

The problem in your code is this expression (and you must have changed it, because it doesn't compile):

[pcolor] n-of 2 neighbors4 = grey

n-of 2 neighbors4 returns an agentset consisting of two randomly chosen patches of the four neighbors. In order to get a list of its colors, you need to use of, so change it to:

[pcolor] of n-of 2 neighbors4 = grey

However, [pcolor] of that agentset returns a list of colors; one for each of the two randomly chosen neighbors. So here are you comparing a list of colors with a color (which is actually just a number). That will always return false.

You will probably want something like:

count neighbors4 with [pcolor = grey] = 2

Edited: mystery solved.

Upvotes: 3

Related Questions