Saturday, 15 March 2014

NetLogo: create a dynamic number of breeds -



NetLogo: create a dynamic number of breeds -

how can create dynamic number of breeds @ runtime? want user able take amount of breeds.

i thought like

to setup_breeds allow j 1 while[j <= n_groups][ breed[j] ] end

where n_groups number of breeds whick taken slider. unfortunatly cannot utilize breed within method...

any ideas?

thanks!

you need explicitly declare each breed breed keyword, short reply is: no, can't have dynamic number of breeds.

but need actual netlogo breeds? main purpose of having different breeds have different variables each breed. if not case, perhaps can away having group-id turtle variable. create number of turtles each of n_groups, like:

turtles-own [ group-id ] setup clear-all allow n_groups 10 allow n-turtles-per-group 5 foreach n-values n_groups [ ? ] [ create-turtles 10 [ set group-id ? ] ] inquire turtles [ set label group-id ] ; turtles of, e.g., grouping 2: inquire turtles [ group-id = 2 ] [ fd 5 ] end

if think really need breeds, edit question tell why, , we'll see if can find solution you.

side note:

i used foreach n-values n_groups [ ? ] loop through n groups. that's equivalent of:

let 0 while [ < n_groups ] [ set i + 1 ]

...but arguably more "netlogo-ish".

netlogo

No comments:

Post a Comment