Setting type variables to Null

BlitzMax Forums/BlitzMax Programming/Setting type variables to Null

MattVonFat(Posted 2005) [#1]
Hello.

In the mini-project i'm doing at the moment, i am trying to create ants which gather food into piles. This is the code i'm having problems with:

Function Collide()
	For T:Item = EachIn ItemList
		If RectsOverlap(T.PosX,T.PosY,3,3,Ant1.PosX,Ant1.PosY,3,3)
			If Ant1.Holding = 0
				Ant1.Holding = T.ID
				T.HAnt = Ant1
			Else If Ant1.Holding > 0 And Ant1.Holding <> T.ID
				T.HAnt = Null
				Ant1.Holding=0
				Ant1.TimeWait=0
				Ant1.Move(Ant1.Angle-180)
			End If
		End If
	Next
End Function


The problem is with T.HAnt = Null. T.HAnt has to point to the Ant which is holding the T (food). (And it is declared in the type as Field HAnt:Ant). I need to set this value to Null for later on. When i first initiate the types with no value for that they are fine and dont do anything. I then assign the Ant to that and it works as the food follows it. But when i set it to Null it acts as though the Ant variable is still attached to it.

I hope this all makes sense.

Can anyone help?

Oh and this is the code that checks if the HAnt = Null just incase it is this bit which is wrong:

Method Move()
        If HAnt
	        PosX = HAnt.PosX
		PosY = HAnt.PosY
	End If
End Method



Perturbatio(Posted 2005) [#2]
this works:

Type TFood
	Field Amount:Int
End Type

Type TAnt
	Field Food:TFood = New TFood
	Method check()
		If Food Then Print "not null" Else Print "Null"
	End Method
End Type

Global m:TAnt= New TAnt

m.check()
m.Food=Null
m.check()


is that essentially what you are trying to do?


MattVonFat(Posted 2005) [#3]
Yes thanks. I guess as i can get that to work there must be another problem and i have my suspicions that its to do with timing.

Thanks for the ehlp.