ID:159514   Feb 24 2009, 4:34 pm Is there an internal way to add something to a list with a preset probability for use in pick()? I need to be able to add things to a list with a certain probability as I loop through them, and then have it pick one. I can code something for it myself if there isn't already something internal for it, I'm just wondering... ex: ```world<
 <-> Feb 24 2009, 4:38 pm Nah, it wouldn't make sense to have some probability feature built specifically into adding to lists or something. Provided I gather what you're trying to do correctly, um, can't you simply do this? ```if(prob(x)) L += "[x]" ```
 <-> Feb 24 2009, 4:41 pm In response to Kaioken Kaioken wrote: Nah, it wouldn't make sense to have some probability feature built specifically into adding to lists or something. Provided I gather what you're trying to do correctly, um, can't you simply do this? ```if(prob(x)) L += "[x]" ``` Possibly, but then I could end up with an empty list even if there was something to pick from. What I'm doing more exactly: Looking at all enemies in oview(), adding them to a list, then choosing one to attack, enemies with a higher threat level get targeted more often.
 <-> Feb 24 2009, 4:47 pm In response to Falacy Looks like what you need is a pickweight() proc, then.
 <-> Feb 24 2009, 4:54 pm (Edited on Feb 24 2009, 5:02 pm) In response to Kaioken Kaioken wrote: Looks like what you need is a pickweight() proc, then. I didn't really read all that, but here's what I'm doing now: (in general) ```proc/ThreatPick(var/list/L) var/list/IndexList=list() var/CurIndex=0 for(var/obj/O in L) CurIndex+=1 for(var/i=1;i<=O.ThreatLevel;i++) IndexList+=CurIndex return pick(IndexList) ``` Then using the returned index to reference an actual Troop obj in the original list. Threat levels vary from 1 to 10.
 <-> Feb 24 2009, 5:04 pm In response to Falacy Falacy wrote: I didn't really read all that You just need to press CTRL-F and read some bits about pickweight(), not the whole article.
 <-> Feb 24 2009, 5:06 pm In response to Kaioken Kaioken wrote: You just need to press CTRL-F and read some bits about pickweight(), not the whole article. Done already, probably more efficient Lummox's way; since it may loop less depending on list size and threat level.