ID:139984
 
Code: Outputting Hair Colours To Grid.
//Creating the list
////////////////////

mob/var/tmp/list/Hairoptions2 = list(new /obj/HairSelection2/haircolor1, new /obj/HairSelection2/haircolor2, new /obj/HairSelection2/haircolor3,
new /obj/HairSelection2/haircolor4, new /obj/HairSelection2/haircolor5, new /obj/HairSelection2/haircolor6, new /obj/HairSelection2/haircolor7,
new /obj/HairSelection2/haircolor8, new /obj/HairSelection2/haircolor9, new /obj/HairSelection2/haircolor10, new /obj/HairSelection2/haircolor11,
new /obj/HairSelection2/haircolor12, new /obj/HairSelection2/haircolor13, new /obj/HairSelection2/haircolor14, new /obj/HairSelection2/haircolor15,
new /obj/HairSelection2/haircolor16, new /obj/HairSelection2/haircolor17, new /obj/HairSelection2/haircolor18, new /obj/HairSelection2/haircolor19,
new /obj/HairSelection2/haircolor20, new /obj/HairSelection2/haircolor21)

//The proc thats called by user once new character is clicked
/////////////
mob/proc/BuildHairColourGrid()
var/Hairs2 = 0
for(var/obj/HairSelection2/O in Hairoptions2)
src << output(O, "haircolour:[++Hairs2]")


Problem description: Now as usual with most my code snippets this works fine more or less.. it does what it needs to do which is a good sign.

Now hopefully with that snippet you are able to determine that the hair choices are indeed objects that have a click command that follows through once they are actually outputted.

My question is this: Is there anyway i could make this more proficient (such as not needing to actually define each and every object in that list)

If you require any more information please drop what you wish to know below and i will supply the information if needed.

-Furthermore im not even sure i need that tmp thing in the list but i put it there just incase (since i dont have a save system as per yet)-

Thanks in Advance
Midget.

var/list/my_list = list()
for(var/V in typesof(/obj/HairSelection2)-/obj/HairSelection2)
my_list += new V
In response to Nadrew
Many thanks to you Nadrew.

Keep up the good work with your guides i also enjoy reading them
In response to Nadrew
Hmmm, I cant get it to work properly.

Its possible i may be missing a step but im not quite sure, As it is it creates the objects and allows me to view them in my grids but they are then unclickable (due to being garbage collect i presume)

Unlike my previous one which allowed them to also be clickable.
In response to Midgetbuster
All you have to do to prevent garbage collection is add them to a list or set a variable to the reference to the object. If there's anything at all referencing the object it won't be collected.

So when you create the object simply add it to a list that belongs to the mob and it'll stay around.