Reputation: 507
I want a random item reported from this list:
set probability-list [["residential" 0.60] ["commercial" 0.30] ["industrial" 0.10]]
The way they are called is:
set land-use first rnd:weighted-one-of-list probability-list last
But I want the weight of each item to be inputted by the user through input boxes in the model's interface, not in the code itself. For this, I added an input box for each item called Res, Com and Ind. So the code for the list is now:
set probability-list [["residential" Res] ["commercial" Com] ["industrial" Ind]]
but Netlogo highlights code with the weight name and the message "Expected a literal value". Can this be fixed?
Upvotes: 0
Views: 2529
Reputation: 2780
When you make a list literal in NetLogo, you can only put other literal items (strings, numbers, booleans) that you type into the code in that list.
To make a "dynamic" list using variables, you have to use the list
primitive with parenthesis:
set probability-list (list (list "residential" Res) (list "commercial" Com) (list "industrial" Ind))
This is outlined in the NetLogo programming guide under lists.
Upvotes: 2