Manage arrays using Lists


Tweet arrays blitzmax code-archives tutorials
(Posted 1 month ago) RonTek

using a list to add, remove and move array items without pain. You want a list ONLY of INT: I think LIST in Bmax handle generic object...unless you write a 'personal' tlist. Or you can 'force' like in the following example:

Author: degac

Global mylist:TList=New TList
Global myArray_cont=0' count how many elements do yoy have - not necessary

Type myarray
Field id
Field val:Int' <--- you declare the type as INT

Function Add:myarray(valore:Int)
Local e:myarray=New myarray
e.id=myArray_cont
e.val=valore
ListAddLast mylist,e' add the element to a list
myArray_cont:+1
Return e
End Function

Function Show()
For Local a:myarray=EachIn mylist
Print "["+String(a.id)+"] = "+String(a.val)
Next
End Function


End Type

For i=1 To 5
myarray.add(i)
Next
myarray.show()

WaitKey
End

Reply To Topic (minimum 10 characters)

Please log in to reply