EachIn

BlitzMax Forums/BlitzMax Beginners Area/EachIn

Also, using inheritence makes it a lot cleaner to update what i think you're trying to update:

Global shipList:Tlist=CreateList()

Type baseUnit
	Field name$
	Field x#,y#,f#
	
	' whenever you make a new object, this method will get called
	' add to the shipList so we don't have to later on.
	'Method New() 
	'	ListAddLast(shipList,Self) 
	'End Method
	
	Method update()
		f:+1 
	End Method
End Type

Type playerUnit Extends baseUnit
	Method update()
		super.update() ' will perform what baseUnit.update() does
		' update keypresses, etc for player
	End Method
End Type

Type AIUnit Extends baseUnit
	Method update()
		super.update() ' will perform what baseUnit.update() does
		
		'do IA code here
	End Method
End Type

Function updateShips()
	For Local i:baseUnit=EachIn shipList
		i.update()
	Next
End Function


' --------------------------------
Local i:playerUnit=New playerUnit
	i.name="player"
	ListAddLast(shipList,i)
	
Local j:AIunit=New AIUnit
	j.name="AI 1"
	ListAddLast(shipList,j)	


While KeyHit(KEY_ESCAPE)=0
Cls

	updateShips()

Flip
Wend
End