Adding/removing array elements?

BlitzMax Forums/BlitzMax Beginners Area/Adding/removing array elements?

mmm. 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:

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


Hope this can be useful. It's based upon generic list of Bmax - using type to add each element