How to determine an objects type

BlitzMax Forums/BlitzMax Beginners Area/How to determine an objects type

WolRon(Posted 2009) [#1]
Hi. I did a quick search but didn't find exactly what I was looking for. Is there a better? way to determine an objects type than by using an ID like in the following code?
Type TGameObject
	Field TypID:Int  '1=TBall  2=Tsomethingelse etc.
	Field X:Float
	Field Y:Float
	'... etc.
End Type

Type TBall Extends TGameObject
	Field '... etc.

'elsewhere...
	For Local o = EachIn GameObjectList
		If o.TypID = 1 Then ...
	Next


Perhaps something like this?
	For Local o = EachIn GameObjectList
		If Self = TBall Then ...
	Next



plash(Posted 2009) [#2]
If you are looking for a certain type of an object (a single type of an object) you can simply do this
For Local o:TBall = EachIn GameObjectList ' Only select TBall objects from the list.


If you want multiples, try this
For Local o:Object = EachIn GameObjectList ' Same as what you're currently doing, but I'm using typenames for the variable(s)
	If TBall(o)
		'...
	Else If TSomethingElse(o)
		'...
	'etc



WolRon(Posted 2009) [#3]
Thank you very much!