ID:157083
 
Hi

Can anybody help me with lists? I've tried and tried to work them out but i can't.

Basically, i need to be able to have a list of objects that is always available with a size of 151 that never changes.

Can anybody help me?
var/const/list/A = list(/1, 2, "3", /4, ...)</DM>

the const makes the variable unchangeable, though if you are introducing new objects or modifying it in run-time, it is best to take out the const. If you are putting in a path of objects and would like those path to be created at run-time, use newlist() instead.
In response to GhostAnime
GhostAnime wrote:
var/const/list/A = list(/1, 2, "3", /4, ...)</DM>

the const makes the variable unchangeable, though if you are introducing new objects or modifying it in run-time, it is best to take out the const. If you are putting in a path of objects and would like those path to be created at run-time, use newlist() instead.

I had a look at the newlist thing, and thats going to be quite hard for a list with a size of 151: a list which may have to grow to 493 in the future...
In response to Darkoro
umm what do you exactly mean by 'size'? If you mean it as the list length then you could have a method.
var/list/The_List == var/list/The_List[0] // both are same and both are just list references
var/list/The_List[151] // this creates a list with length 151


and this is how you set any value in the list

The_List[1]="One" // the first index of the list is now the string "One"
The_List[2]=2 // thee second index is now the integer floating value 2
The_List[3.... and so on till 151]

If I am wrong then I can join with you for learning!

EDIT: The above listed lists are empty.Its just like a jeans with 151 pockets but nothing in it.
In response to Darkoro
Just initialize it at runtime (world/New() perhaps), by going through typesof() to get a list of types and adding a new instance of each to the list.
In response to Garthor
thnx Garthor for letting me see what he wanted!
proc/get_thelist()
var/list/templist=typesof(/obj/theobj)
.=newlist(templist)


That or This is what you want.

proc/get_thelist2()
var/list/My_List[151]
for(var/i=My_List.len,i>0,i++)
My_List=new/obj/theobj // this causes all index in the list to have the same type of obj.And there would be 151 such objs.


Lets Elaborate this.

First Case:
Suppose you have the 'obj' data tree like this
obj // the byond specified datum
theobj // the 'you' specified datum
theobj_kid1 // first kid of theobj
theobj_kid2 //second kid of theobj
aobj // a kid of 'obj' and the parent of aobj_kids(including 1 and 2)
aobj_kid1 // kid of aobj
aobj_kid2 // kid of aobj


Keep the family tree on ur mind.

/*
What is typesof()? Use the reference!
I ll Illustrate
typesof(obj) --> gives a list = list(/obj,/obj/theobj,/obj/theobj/theobj_kid1,/obj/theobj/ theobj_kid2,/obj/aobj,/obj/aobj/aobj_kid1,/obj/aobj/ aobj_kid2)

so typesof(obj) returns the type /obj and all its kids(derivatives)

now you can figure out that
typesof(theobj) makes a list containing /obj/theobj,/obj/theobj_kid1,/obj/theobj_kid2.

newlist(list(A,B,C))/* is same as */list(new A,new B,new C)
/*in our case*/ newlist(templist)=list( new/obj/theobj, new/obj/theobj_kid1,new/obj/theobj_kid2)


This procedure loads all derivatives of theobj in to the list.

Case Two:

This should be pretty much easy to understand, and I dunno if it is the efficient way.

so first it creates a My_List of size 151.
Then it goes for a for loop, and creates a new instance of 'theobj' and assigns it to every index of the My_List.

This will give you a list containing 151 'theobj's!

if you can be more specific probably I would exactly know what you are trying to do.
In response to Soul Sign
Soul Sign wrote:
thnx Garthor for letting me see what he wanted!
> proc/get_thelist()
> var/list/templist=typesof(/obj/theobj)
> .=newlist(templist)
>

That or This is what you want.

> proc/get_thelist2()
> var/list/My_List[151]
> for(var/i=My_List.len,i>0,i++)
> My_List=new/obj/theobj // this causes all index in the list to have the same type of obj.And there would be 151 such objs.
>

Lets Elaborate this.

First Case:
Suppose you have the 'obj' data tree like this
> obj // the byond specified datum
> theobj // the 'you' specified datum
> theobj_kid1 // first kid of theobj
> theobj_kid2 //second kid of theobj
> aobj // a kid of 'obj' and the parent of aobj_kids(including 1 and 2)
> aobj_kid1 // kid of aobj
> aobj_kid2 // kid of aobj
>

Keep the family tree on ur mind.

/*
What is typesof()? Use the reference!
I ll Illustrate
typesof(obj) --> gives a list = list(/obj,/obj/theobj,/obj/theobj/theobj_kid1,/obj/theobj/ theobj_kid2,/obj/aobj,/obj/aobj/aobj_kid1,/obj/aobj/ aobj_kid2)

so typesof(obj) returns the type /obj and all its kids(derivatives)

now you can figure out that
typesof(theobj) makes a list containing /obj/theobj,/obj/theobj_kid1,/obj/theobj_kid2.

> newlist(list(A,B,C))/* is same as */list(new A,new B,new C)
> /*in our case*/ newlist(templist)=list( new/obj/theobj, new/obj/theobj_kid1,new/obj/theobj_kid2)

This procedure loads all derivatives of theobj in to the list.

Case Two:

This should be pretty much easy to understand, and I dunno if it is the efficient way.

so first it creates a My_List of size 151.
Then it goes for a for loop, and creates a new instance of 'theobj' and assigns it to every index of the My_List.

This will give you a list containing 151 'theobj's!

if you can be more specific probably I would exactly know what you are trying to do.

Basically, im helping a mate make a pokemon game, and we are starting with the first 151 pokemon. However, we are using DNA to merge with the humans to make a Gijinka.

anyway, i need to create a list with each of the 151 different DNA objects in it that i can access on a whim when i need to in the code.
In response to Darkoro
I assume your DNA requires graphics. But anyway here's how.

//The DNA2List()
//this is your DNA obj tree
obj
god_of_DNAs // All the 151 DNA's are the kids of this obj
var/pokemon_color
var/pokemon_type
var/pokemon_eyecolor
var/pokemon_nature // and all genes can be varred over here
First_Pokemon
pokemon_type="grass" // or wat ever you want
// in the same manner set the information of the p'mon DNA
Second_Pokemon
//blasasasa
Third_Pokemon
//.... .... ... ...
//till the 151th PokeMon
var/global/DNA_List
proc/DNA2List()
var/list/temp_list=typesof(/obj/god_of_DNAs)
temp_list-=/obj/god_of_DNA // remove the god else there will be 152 pokemon dna's. (this is because typesof() also includes /obj/god_of_dna.But we need only from the first pokemon's _dna to the last dna
DNA_List=newlist(temp_list)
return DNA_List

DNA2List() returns a list of DNAs which is directly assigned to the global list 'DNA_List'. So you can access the DNA_List from your home to anywhere in the globe.

so now retrieving information from the list is like:
proc/Get_DNA_Info(var/index) // index is the DNA number ex(1,2,3,...151)
var/obj/god_of_DNA/dna=DNA_List[index] //
var/dna_type=dna.pokemon_type //retrieve the info pokemon_type


Hope that clears.
In response to Soul Sign
That has helped a lot, thanks soul sign.

I have one final question:

I am trying to make a GM/MGM verb that allows the user to give another member a DNA file from the list of 151. Any ideas how i could go about doing this?

Heres what i had:

mob/MGM/verb
Give_DNA_File(mob/M in world, obj/O in DNA_List)
M.contents += new O


But this will not allow me to pick an object in the list on run-time.

Any thoughts?
In response to Darkoro
If O is an instance of an object, "new O" is invalid: the thing that follows the new keyword needs to be a type. Use "new O.type" instead.
In response to Garthor
All I'll do is explain what Garthor said. =P

Garthor wrote:
If O is an instance of an object, "new O" is invalid: the thing that follows the new keyword needs to be a type. Use "new O.type" instead.

yes, as he said new must be followed by a type.
Whats a type ? (/obj/Head) this is a type. but 'Your Head' is not a type it is an instance.But the type of 'Your Head' is /obj/Head.So My Head, Your Head and all Heads in the Universe are instances but they are all of the same type /obj/Head. (probably you know this already, so ignore this paragraph )

Wrong and Why ?
> mob/MGM/verb // ok
> Give_DNA_File(mob/M in world, obj/O in DNA_List) // i ll reform this line later
> M.contents += new O // wrong : new is supposed to be followed by a type and not an instance or object.\because O here is an instance.
>


Correction and How ?
mob/MGM/verb
Give_DNA_File(mob/M in world,obj/O in DNA_List) // this should work if it doesn't try the next code block discarding the obj argument in this line
/*var/obj/O=input("Choose the DNA","DNA Giver") as null|anything in DNA_List
if(!O)
src<<"You canceled the Give!"
return*/

M.contents += new O.type // as Garthor said.
>