Keeping an array/list-length
BlitzMax Forums/BlitzMax Programming/Keeping an array/list-length
| ||
What's a good way of keeping an array (or a list of numbers) a given length? for example: i want to have a list of 8 numbers and when i add a new one, all entries should shift in place and the last one should be removed. ListAddFirst seems to be a nice way to do this, but for removing the last item, i need a reference to that one and B3D-style (something like last:Item = last Item) doesn't seem to work in Bmax. What's an efficient way to do this? |
| ||
Type bob Global list:TList = New TList Field bla:Int Method New() list.AddFirst Self If list.Count()>8 list.Remove list.Last() EndIf bla = Rand(0,100000) EndMethod EndType For Local k:Int = 0 Until 100 Local b:bob = New bob Print "bobs: "+bob.list.count() Next |
| ||
thanks a lot, that is *exactly* the info i need. another question arises: where could i've found the availability of functions like list.Remove and list.Last() myself? The list-section in the Bmax-IDE help doesn't seem to mention them at all. Or am i looking in the wrong place? (help>modules>lists) |
| ||
If you look in the help, you will see it described in the TList type section. Actually there is a RemoveLast() method as well. |
| ||
thanks again. i assumed the elements in the tree-view were all that would be discribed in the full TList-page. overlooked the methods completely |