Search code examples
netlogoagents

ask one agent set to get a value from another agent set


My sellers set trade_Price with this code:

ask buyers  [ ask sellers [if any? buyers-here [ if seller_Price <= [buyer_Price] of myself 
       [ set trade_Price  seller_Price + random ([buyer_Price] of myself - seller_Price) ]]]] 

I want that my buyers also took the same trade_Price if they have a seller in the same patch.(if any? sellers-here). and I code it so:

ask sellers [ ask buyers [if any? sellers-here [set trade_Price ( [trade_Price] of myself )]]]

I think its wrong code because I got different trade_Price s from my agent couples. Do you have any idea how can I set it? Best reagrds


Solution

  • As far as I can tell, you're trying for something like this:

    ask buyers [
      let candidate one-of sellers-here
      if candidate != nobody [
        set trade_Price [trade_Price] of candidate
      ]
    ]
    

    Note that there is no ask sellers around this. You only want each buyer to run this once each time through go.

    Note that if there are multiple sellers on the patch, one-of sellers-here picks one randomly.