netlogo

Recursively assigning types to agents


I'm writing a model in which I need to divide my population of agents into four types. I want to insert a string input in the interface so that I can write a 4-vector of numbers detailing the number of agents for each type, and then numbering the types from 1 to 4 from there.

I've tried:

to setup-players
  let type-distribution read-from-string n-of-players-for-each-type
  
  let i 1
  foreach type-distribution [ j -> 
    create-players j [
      set type i                          
      set payoff 0 
      set strategy (random 11)
      set strategy-after-revision strategy
    ] 
    set i (i + 1)
  ]
  
  set n-of-players count players
end

NetLogo gives an error message saying that the set command requires two inputs. What's wrong with my code?


Solution

  • I suspect that the problem is in the use of type as a variable. type is a NetLogo primitive (for output) and thus cannot be used as a variable name. I'm surprised that you did not get an error to that effect when you first used it in (I presume) a players-own statement.