ID:1780940
 
Keywords: programming
(See the best response by Mr_Goober.)
I've been wondering on how to manage this. I've been trying to create a list that includes all objects in it. I will use this list to later include it in an if statement

if(a in objs) Like that. Thing is, I don't have a clue on how to include all of the objects inside a list! Thanks!
If the list includes all objects in it, then (a in objs) is definitely always true.
In response to Kaiochao
No. That is an undefined variable. I need to create the "objs" list, but I don't know how to include all objects in it.
In response to Kirshen
You're trying to check if an object exists?
Oh. . how to make a list contain all objects. Very easy, something I learned thanks to I believe Albro.

var/list/OBJS = list() // creates the list

/* For the next part, you need to have a proc that prompts the addition
of all objects to the pre-made list.
Such as Login(). Made verbs or procs will also work.*/


mob // mobile. .
Login() // built in proc that activates when you log in. .
for(var/t in typesof(/obj))// defines the variable 't' in all objects that are /obj. So it includes EVERYTHING that would eventually be defined under obj
OBJS.Add(new t) // For t (which is now all objects), add to your OBJS list.


Indentation is off since I don't my DreamSeeker on. Hope this is what you meant.

Why not just use OBJS.Add(t) in /obj/New? This will impact your performance by quite a bit. My way will make sure every object is added to the list (Naturally you'll have to get rid of it on Del()) but it won't have to loop at every login.
Best response
If you need to iterate through all /obj types that currently exist, use:
for (var/obj/o in world)

This will return all /obj types, as well as derived types from /obj.
It shouldn't be that hard. Just override obj.New() and obj.Del():
var/tmp/list/objs = list()

obj
New()
objs += src

Del()
if(src in objs)
objs -= src
..()

Now when any obj is created, it will be automatically added to the objs list, and when it's destroyed it will be automatically removed from the list.

Just be sure that if you override New() or Del() for any subtype of /obj, such as /obj/rock, that you call the default action ..().