Help with Casting

BlitzMax Forums/BlitzMax Beginners Area/Help with Casting

Eric(Posted 2006) [#1]
Looking at the Code snipet Below. In the Universe Type, UpdateAllObjects function. How can I cast if the Objects:Universe is a Tplanet or TShip.

What I have does not work. This code will not run as is because I removed a lot of stuff to post.

The Error I get is Expression of Type Universe can't be invoked.

Thanks in Advance for any help

Global ObjectList:Tlist=New Tlist 


Type Universe
	 
	Method Draw() Abstract 
	
	Method remove()
		Link.Remove
	End Method
	
	Method AddLast( list:TList )
		Link=List.AddLast( Self )
	End Method
	
	Function DrawAllObjects()
		For Local Objects:Universe=EachIn ObjectList
			If Objects(TPlanet)<>Null 
			'	DrawText "Planet",Objects.Position.X,Objects.Position.Y+60
			End If 
			Objects.Draw()
		Next
	End Function 
End Type 

 
Type TPlanet Extends Universe
	Method Draw()
		DrawOval Position.X-25,Position.Y-25,50,50
	End Method 
	Function Create:TPlanet(X:Float,Y:Float,M:Float)
		Local Planet:TPlanet=New TPlanet
		Planet.AddLast(ObjectList:Tlist)
		Return Planet
	End Function 

End Type 
Type TShip Extends Universe
 
	Method Draw()
		DrawRect Position.X-2,Position.Y-2,5,5
	End Method 
	Function Create:TShip(X:Float,Y:Float,M:Float)
		Local Ship:TShip=New TShip
		Ship.AddLast(ObjectList:Tlist)
		Return Ship
	End Function 
End Type 
 
Repeat 
	Cls
	 
	Universe.DrawAllObjects()	
	
	 
	Flip  
Until KeyHit(Key_Escape)



Eric(Posted 2006) [#2]
It's funny how you can work on a problem, finally ask for help and then figure it out 5 mins later.

Function DrawAllObjects()
   For Local Objects:Universe=EachIn ObjectList
	If TPlanet(Objects)<>Null ' <------- I had Tplanet and Objects Reversed. :)
	DrawText "Planet",Objects.Position.X,Objects.Position.Y+60
	End If 
	Objects.Draw()
   Next
End Function