Why does this piece of code keep error-ing on me?

BlitzMax Forums/BlitzMax Programming/Why does this piece of code keep error-ing on me?

Pineapple(Posted 2010) [#1]
"Attempt to access field or method of Null object" on the "nets.remove highest" line. At the time of this loop there are 7 net objects in the nets list. How can I possibly be getting this error? It always occurs the second time this piece of code is gone through.

	Local on%=0
	For Local n:net=EachIn nets
		If on=0 Then lowest=n
		If n.score<=lowest.score Then lowest=n
		If on=0 Then highest=n
		If n.score=>highest.score Then highest=n
		on:+1
	Next
	nets.remove highest



_Skully(Posted 2010) [#2]
I'm assuming lowest and highest are defined previous to this

        lowest=nets.first()
        highest=lowest
	For Local n:net=EachIn nets
		If n.score<lowest.score Then lowest=n
		If n.score>highest.score Then highest=n
	Next
	nets.remove(highest)


try that.

Last edited 2010