Question about Lists
BlitzMax Forums/BlitzMax Beginners Area/Question about Lists
| ||
Hi i have a question about lists, how can i know the value on a position on the list? For example if i have a list with 10 objects and i want to know the value on the fiith value how can i make it? And if i have a list of types created by me, how can i, knowing the tlinks of diferent values of the list, use his values. I tryed TlinkAux.Value() but it doesnt let me use the methods of my type :/ |
| ||
Value stores objects of type "object", so you have to typecast to your type before using Fields/Method of your type: firstentry:mytype=mytype(mytypelist.FirstLink().Value()) To get an element by "index", you have to enumerate through the list for n elements. At least I know no other method to achieve this. |
| ||
Thank you jake! :D |
| ||
..or use an array of those objects. Add a new object to your array (your list, in a way) using slices. |
| ||
As you probalby know, all User types are derived from the base object called "Object". (Talk about nameing policy) When you make a list it doesnt matter what you said you are storing in it. You are storing the "object". So when it comes to access the objects fileds and stuff, you need to "cast" the object back to what it originaly was. |
| ||
Try this as well:' ----------------------------------------------------------------------------- ' ccListIndex ' ----------------------------------------------------------------------------- Function ccListIndex%(list:TList, value:Object Var) 'Loop through a list and return the index of the matching object. Local index = 0 For Local o:Object = EachIn list If o = value Then Return index index:+1 Next 'No match Return -1 End Function |