pick(4;0.75, 2;0.5, 1;0.25)
how about:
pick(0.75 = 4, 0.5 = 2, 0.25 = 1)
(ie, make it do it via the same syntax as list())
ID:2245236
May 9 2017, 1:23 pm
|
|||||||
| |||||||
The fact that pick() has its odd syntax has always irked me.
pick(4;0.75, 2;0.5, 1;0.25) how about: pick(0.75 = 4, 0.5 = 2, 0.25 = 1) (ie, make it do it via the same syntax as list()) |
May 9 2017, 1:28 pm
|
|
Agreed, but I imagine changing the syntax of something that's been around as long as pick() would be hairy. I suppose it could throw a warning if it came across pick() with ; on new compiles though.
|
Frankly I never use the probability syntax for pick(); I prefer to roll my own routine called pickweight() and use that instead, the only downside being that you can't pick from a list of numbers because they're not valid associative keys.
|
Pick would be useful if the weighting was at least accessible at runtime instead of just compile time. It's a giant oversight.
|
Well, if you had prob accept text and automatically turn into numbers, you'd have an easy way writing a script that picks a var from a list depending on its probability, which might be nice. Might be highly unwhatever in terms of syntax as you'd need pick to take a text var:
area mob/player/proc Well, in terms of syntax this is a horrible idea, but it might be useful:, it would be helpful, not needing to somehow separate the prob's value from the actual variable, so easy to store and also easy to write as it doesn't require me to know how long the list is etc.etc. |
Personally I would rather the syntax was list(item = weight) instead of list("weight" = item)
|