ID:1695613
 
(See the best response by Kaiochao.)


Problem description:

Honestly, I was just writing a proc and found myself typing 'pick(/type/) in'- so; I know this isn't the correct behavior for pick(), but is there any existing proc allowing for this behavior? I was looking with no luck yet. If not, I'll have to work around it.
Perhaps typesof() which provide the path you entered and its subpaths.
world << pick(typesof(/Test) - /Test)  //  Pick any type that derive from /pathexcluding /Test itself
Test
A
B
C
Not what I was intending; I was trying to randomly select a entry from a list, but only one of a certain type.

In this specific case, I was trying to randomly select a type of mob from the world, to set a client's eye to.
Couldn't you just do something like this?

proc
pick_type(type, list/list){
var/list/result[] = list();

for(var/datum/t in list){
if(t.type == type){
result.Add(t);
}
}

return pick(result);
}


http://puu.sh/c6b4T/49eddad46d.png
Best response
I don't think there's a built-in way to do this. There's a pretty obvious workaround, though.

proc/pick_type(stuff[], type)
var subset[0]
for(var/datum/d in stuff)
if(d.type == type)
subset += d
return pick(subset)
obj/poo
New(xname)
name = xname
obj/pee
New(xname)
name = xname

var/Waste = list() // Global list of poos and pees.


proc/RandomPoo()
var/tmp/poolist = list()
for(var/obj/poo/P in Waste) // We only want poos in this new list.
poolist += P
var/tmp/i = rand(1, length(poolist)) // The "random" aspect of it.
var/obj/poop = poolist[i] // since we can't exactly return poolist[i].name, we store it in a new obj.
return poop.name


mob/Login()
Waste += new /obj/poo("Corn Wallace")
Waste += new /obj/poo("Mr. Hanky")
Waste += new /obj/pee("Mr. Tinkles")
Waste += new /obj/pee("Watch_Dogs")

world << RandomPoo()



There's probably a better method for it, but if you compile this, the program should only output the names of those in the poo family.
In response to NNAAAAHH
NNAAAAHH wrote:
Not what I was intending; I was trying to randomly select a entry from a list, but only one of a certain type.

In this specific case, I was trying to randomly select a type of mob from the world, to set a client's eye to.

"type" isn't a physically existing atom, you wouldn't be able to set client.eye to it.
In response to Ishuri
Ishuri wrote:
NNAAAAHH wrote:
Not what I was intending; I was trying to randomly select a entry from a list, but only one of a certain type.

In this specific case, I was trying to randomly select a type of mob from the world, to set a client's eye to.

"type" isn't a physically existing atom, you wouldn't be able to set client.eye to it.

I don't think hes trying to return the type itself but objects of said type and randomly "pick" one of said objects to return of said type.


for example: http://puu.sh/c6b4T/49eddad46d.png
Thanks, I wad mainly asking if there were a built-in feature so to prevent needless processes and ultimately, needless use of resources. I'll likely submit a feature request and just keep to a work around, as suggested
Gokussj99 wrote:
Kaiochao wrote:
I don't think there's a built-in way to do this. There's a pretty obvious workaround, though.

> > proc/pick_type(stuff[], type)
> > var subset[0]
> > for(var/datum/d in stuff)
> > if(d.type == type)
> > subset += d
> > return pick(subset)
> >

and ofcourse kaio gets the vote even though his code has errors :P


That's why you don't just copy and paste.