Python List Search wrong

Is there somthing wrong with the List search functions in Python in BGE??

this is like its sick.

import GameLogic as GL
cont = GL.getCurrentController()
own = cont.owner
scene = GL.getCurrentScene()
P = GL.P1

Mlist = own.children
print Mlist
print Mlist[0]
print "OBTitle.003" in Mlist
#Mlist.index("OBTitle.003")

so

print "OBTitle.003" in Mlist >>> True

and

Mlist.index("OBTitle.003") >>> Error list.index(x): x not in list

can sombody tell me whats going on here??
did i forgot somthing?

I’m guessing that your problem has to do with datatypes.

The list datatype is a generic type that can store lots of different datatypes. It’s basically an array with some fancier functions.

The list.index function takes a value to look for in the list. However, the actual OBJECT OBTitle.003 isn’t equal to the STRING OBJECT “OBTitle.003”.

For example, let’s say you had an object called “test” and you ran the following script:


own = GameLogic.getCurrentController().owner

print own == "OBtest"

This would print “False” because a String type object isn’t the same as a KX_GAMEOBJECT (as they’re called in Blender). The index command is doing == comparisons, and it isn’t finding a String type object.

However, if you do this:


Mlist.index(scene.objects['OBTitle.003'])

Then it’ll correctly work, because scene.objects gets the actual object itself, not just a String that’s only equal to the object’s name.

I hope that’s a sufficient explanation!

-Sam

This is like a dream.
the first post helps and solves the problem at once.
thx “great” Sambassador.

greets Equal