TList
BlitzMax Forums/BlitzMax Beginners Area/TList
| ||
I know you can have a list of objects, but can you also have a list of values? If so, how? |
| ||
If you mean values as in Int/Float etc, you need to use either arrays or a type that holds the value in a field. |
| ||
do you mean arrays? something like this: Local pencil_Boxes:Int[10] pencil_boxes[0] = 4 ' this box has 4 pencils pencil_boxes[1] = 6 ' and this box has 6 pencils Print pencil_boxes[0] Print pencil_boxes[1] Arrays in BlitzMax are very versatile. (sometimes even moreso than lists) An Array can hold a number (i.e an int, a float, Double, etc) or can hold a String ( "foo" ) you can resize them on the fly by using slices: Local foo:String[] foo = foo[..2] ' a slice foo[0] = "Hello" foo[1]= "GoodBye" Print "foo has " +Len(foo)+ " Elements" Print foo[0] Print foo[1] |
| ||
Note that resizing an array is considerably slower than adding an element to the end of a list, while accessing an element in an array is considerably faster. If you want a TList of values, you have to wrap the values in a type, as grable mentioned. For example: type IntWrapper field Value:int Endtype Then you store instances of IntWrapper in the list. |
| ||
Right, ok. Thanks all. |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=67497 |