monkey equivalent isKindOfClass?

Monkey Forums/Monkey Programming/monkey equivalent isKindOfClass?

NoOdle(Posted 2011) [#1]
Just wondering if there was an equivalent in monkey to check wether an object is of a certain class?

I know its possible in Obj-C and I have used it a lot but not sure if other targets and monkey support it...


slenkar(Posted 2011) [#2]
local o:Int=35
if Int(o)
(returns true)
if Float(o)
(returns false)

Float(o) converts o into a float


NoOdle(Posted 2011) [#3]
Ok I had to think about that for a second... your example pointed me in the right direction but fails if you swap the if around as ints can be cast into floats and vice versa.

Tested it with class objects of my own and it does indeed work, you cant cast from class to class... don't know why I didn't think of that.

Thanks!


slenkar(Posted 2011) [#4]
yw :)

you cant cast from class to class.

well you can if one extends the other


bruZard(Posted 2012) [#5]
how can i check this:
If Camera(entity) ....


Camera is extends Entity, but how can i test that? My function gets the object as type of "Entity", but it can be a mesh, a light, camera .......


bruZard(Posted 2012) [#6]
ok, i am tired ... works like other types ... should go to bed :D
Function MoveEntity:Void(entity:Entity, x:Float = 0.0, y:Float = 0.0, z:Float = 0.0)
	If Camera(entity)
		' now we have to transform every object in this f.. fine world
	EndIf
	entity.move(x, y, z)
End