ID:171226
 
QUOTE FROM DM REFERENCE "Also, to pick a value randomly from a list, simply pass the list as the sole argument into pick(). In this case, there is no provision for weighting the probabilities. All items in the list are equally likely."

Now, when picking from a list, i notice ALL the things in the list are being picked,

Heres my code:
mob/proc
ChooseBMAN()
var/mob/list/result
result = pick(bomblist)
if(!result)
ChooseBMAN()
else
result.thebomb = 1
view() << "[result] is the bomb!!!"
result.verbs += /mob/mini_games/verb/bombverb
world << "<B>[result],[result],[result]"
return

the list is a global var defined like this:
mob/var/global/list
bomblist = list()

any one know the problem?

Ive tested with 3 people, all 3 were added to the global list, and all 3 were picked by pick()

Thanks in advance

Farkas
Does it work if you change the line var/mob/list/result to just var/mob/result ?
Try this instead:

mob/proc
ChooseBMAN()
var/result = pick(bomblist)
if(!result)
ChooseBMAN()
else
result.thebomb = 1
view() << "[result] is the bomb!!!"
result.verbs += /mob/mini_games/verb/bombverb
world << "<B>[result],[result],[result]"
return

var/list/bomblist = list()


In response to DeathAwaitsU
no & no didnt work, still same problem, thanks for the quick reply though
Well, it's kinda difficult to tell what you're trying to do here, or for that matter what's happening. Your description of the problem doesn't make too much sense. What do you mean that all things are being picked?

Also, you shouldn't at all be doing this:
result = pick(bomblist)
if(!result)
ChooseBMAN()


The reason why is simple: If result is always null, this proc will call itself forever, until the stack overflows. When a proc calls itself as a way of looping, you have to use spawn() or you get infinite recursion. But that's still a poor choice for that loop; this is better by far:
while(!result)
result = pick(bomblist)


Of course, that makes no sense either in the big picture. If you had a list full of nulls, this would loop forever, and really you should take out the nulls entirely before picking.
while(bomblist.Remove(null));   // cull the nulls


But once you've done that, you're still not accounting for a case where bomblist is empty. In that case you should return right away, and do nothing. This, then, is what it should look like:
while(bomblist.Remove(null));
if(!bomblist.len) return
var/mob/result = pick(bomblist)


That's based only on my guess at what this proc is really meant to do, of course.

Lummox JR
In response to Lummox JR
what i am trying to do here is randomly pick one player from the list, yet, when i tried this with 3 players, all 3 were picked!
In response to Farkas
Farkas wrote:
what i am trying to do here is randomly pick one player from the list, yet, when i tried this with 3 players, all 3 were picked!

What you're saying there still makes no sense. In the proc as you had it, clearly it doesn't say three different things at once. Only one mob at a time can fill in "[result] is the bomb!!!"

So again, what do you mean when you say all 3 were picked? What exactly was output, how often, in what order, and when did it stop? And I'd like to see what other proc calls this, because if the proc is being called in a wrong way to begin with it could be screwing with your results.

Lummox JR
In response to Lummox JR
Thanks for asking those questions Lummox, I started thinking about how I was calling the proc and who was, I have now fixed the problem.

Thanks again,

Farkas