Bobby M
Bobby M

Reputation: 159

how to set a patch-variable as the number of turtles-here

I want to set a patch variable as equal to the number of turtles on that patch.

I have tried

ask patches [set variableA (count turtles-here)]

when i do this, i get the error: "set expected 2 inputs"

i tried to use a workaround by setting the turtle-count as the plabel

ask patches [set plabel (count turtles-here)]

that code worked, but i need to do this for multiple variables and when i tried to transfer the plabel over to the variable

ask patches [set variableA plabel]

i again get the error: "SET expected 2 inputs"

any help is appreciated.

Upvotes: 4

Views: 1933

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

Are you sure that variableA is truly a patch variable? If it is, your first line should work. The following program, for instance, compiles and executes without error:

patches-own [ variableA ]

to test
  ask patches [ set variableA (count turtles-here) ]
end

The only case I can see that would be causing the error that you're seeing is if variableA is not a patch variable, but a reporter taking one argument. For example:

to test
  ask patches [ set variableA (count turtles-here) ]
end

to-report variableA [ x ]
  report 0
end

...will give you the SET expected 2 inputs error.

Upvotes: 3

Related Questions