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?
ID:157083
![]() May 27 2010, 8:10 am
|
|
This might help a bit also: http://gug.com/byondscape/ascape.dmb/LummoxJR.2002-0103/
|
GhostAnime wrote:
var/const/list/A = list(/1, 2, "3", /4, ...)</DM> 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... |
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 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 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. |
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.
|
thnx Garthor for letting me see what he wanted!
proc/get_thelist() That or This is what you want. proc/get_thelist2() Lets Elaborate this. First Case: Suppose you have the 'obj' data tree like this obj // the byond specified datum 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) 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. |
Soul Sign wrote:
thnx Garthor for letting me see what he wanted! > proc/get_thelist() That or This is what you want. > proc/get_thelist2() Lets Elaborate this. > obj // the byond specified datum Keep the family tree on ur mind. > newlist(list(A,B,C))/* is same as */list(new A,new B,new C) This procedure loads all derivatives of theobj in to the list. 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. |
I assume your DNA requires graphics. But anyway here's how.
//The DNA2List() 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) Hope that clears. |
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 But this will not allow me to pick an object in the list on run-time. Any thoughts? |
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.
|
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 Correction and How ? mob/MGM/verb |
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.