OC2PS
OC2PS

Reputation: 1069

Get a count of turtles with a combination of values

I am trying to count the number of "buyer" type turtles, which have a certain surplus (turtle variable) greater than or equal to zero, and price (another turtle variable) greater than the current turtle's price (already grabbed in local variable myprice...although there may be a more direct way to put it in)
let countup count buyers with ([surplus >= 0] and [price > myprice])
NetLogo returns

Expected a TRUE/FALSE here, rather than a list or block.

let countup count buyers with (surplus >= 0 and price > myprice) returns

WITH expected this input to be a TRUE/FALSE block, but got a TRUE/FALSE instead

Upvotes: 0

Views: 235

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

Close! You're looking for:

let countput count buyers with [ surplus >= 0 and price > myprice ]

with is a report that takes two arguments, like so

<turtleset> with <report block>

where the reporter block is a clump of code surrounded by [ ] that will result in either true or false. In general [ ] is netlogo's way of grouping together code so you can doing something special with it, such as having each agent in an agentset run it. Hope that helps!

Also, I assume you've got something like let myprice price on, say, the line above this one. You can combine those lines like so (not saying this code is the right way to do it, just wanted to show another option):


let countput count buyers with [ surplus >= 0 and price > [ price ] of myself ]

Checkout the docs for (the very poorly named) myself.

Upvotes: 3

Related Questions