ID:270433
 
How would I go about creating a list of objects that, say are not of type exampleType and don't have the name of ""? I tried several things that weren't, and aren't successful.


--Vito
var/list/Things=list()
for(var/obj/O)
if(istype(O,/obj/Example)||O.name=="Example") continue
Things+=O


That would loop through all objects, and exclude anything of type /obj/Example, or with the name "Example" from the list. Hope that's what you're looking for.
In response to Detnom
Okay, thanks.
I like quick solutions...


--Vito
In response to Vito Stolidus
Umm, not so quick. I came up with:
var
list/Things1=list()
list/Things2=list()
list/Things3=list()
for(var/obj/Oo)
if(istype(Oo,/obj/nocreate)||istype(Oo,/obj/hud)||Oo.name==""||Oo.name=="overlay") continue
Things1+=Oo
for(var/turf/Oo)
if(istype(Oo,/turf/nocreate)||Oo.name=="") continue
Things2+=Oo
for(var/mob/Oo)
if(istype(Oo,/mob/othernpc)||Oo.name=="") continue
Things3+=Oo

I don't know why or how, but there's an infinite loop in one of those 3. Where? I can't find it. Is it a really stoopid mistake or oversight?

A somewhat related question: Does that run through every obj, mob, or turf type in the world, or does it run through every one coded?


--Vito
In response to Vito Stolidus
That little bit of code will run through every single obj mob and turf in your world, the problem with the infinite loop you are having is probably with the turfs because there are usually so many of them.
In response to Deathstar175
Ah, will it now? I thought it would only run through a list of possible type paths... Is there a way to do that?


--Vito
In response to Vito Stolidus
Ohh, that's what you were after? Sorry for the misunderstanding, this may be more up your alley.
var
list
initial_variables[0] //For holding the initial vars
Objs=list()
Turfs=list()
Mobs=list()
proc/List_Atoms()
Objs=typesof(/obj/)
Objs-=typesof(/obj/nocreate/,/obj/hud/)
Objs-=/obj/
for(var/O in Objs)
var/t=initial_from_type(O,name)
if(t==""||t=="overlay") Objs-=O
Turfs=typesof(/turf/)
Turfs-=typesof(/turf/nocreate/)
Turfs-=/turf/
for(var/T in Turfs)
var/t=initial_from_type(T,name)
if(t=="") Turfs-=T
Mobs=typesof(/mob/)
Mobs-=typesof(/mob/othernpc/)
Mobs-=/mob/
for(var/M in Mobs)
var/t=initial_from_type(M,name)
if(t=="") Mobs-=M

proc/initial_from_type(type, variable)
var/list/L=initial_variables[type]
if(!(variable in L))return 0
return L[variable]

proc/setup_initial_variables()
var
datum/D
list/L
for(var/type in typesof(/datum))
D = new type;L=new
for(var/V in D.vars)
L[V]=D.vars[V]
initial_variables[D.type]=L
del(D)

Okay, I ran into a bit of trouble checking the names, thankfully I found a proc courtesy of Loduwijk that helped.
Dont forget to run setup_initial_variables() in world/New().
You'll also want to make sure to remove any other paths you dont want people to be able to create, as I did with /mob/, /obj/ and /turf/.
In response to Detnom
Ah... Well, I guess I didn't say what I wanted properly, and I misunderstood what leaving the in world out of the for loop would do. Thanks.


--Vito
In response to Vito Stolidus
One final question... What is this about the array initial_variables? What should it be initialized as? How long? You did not define it, and I don't know how long to make it.


--Vito
In response to Vito Stolidus
That part of the code was right out of an old post by Loduwijk, and the proc setup_initial_variables() should take care of initial_variables for you. Just run the proc in world/New().

-Edit-

To explain a little further what the array is for, variables can't just be read from a typepath without an instance of the path being created. With objs and mobs that's not a problem, we could just make a mock of each one, check its name, then delete it, but when it comes to turfs, it's a bit more complicated. initial_variables will store each typepath, and its variables to a list, that can be accessed with the other proc, initial_from_type(type,var).
In response to Detnom
initail_variables was read as undefined. I put a call to setup_initial_variables() in world/New(). You need initial_variables defined, with a predefined length, to make all that work, as far as I can tell.

I get runtime errors yelling about "bad index" at world start, and about 50 more when the proc that this is all used in is called.

What did I do wrong here? setup_initial_variables() remains unchanged. The only thing I did was defining initail_variables. It doesn't work defined as a list or as an array of unspecified length.


--Vito
In response to Vito Stolidus
var/list/initial_variables[0]

That should do it.
In response to Loduwijk
Okay... I'll try.

[edit]: Fixed. Thanks all.

--Vito