python list search (matching) not working????

Hey there
I have been working on a game for some weeks now
I bought a new laptop recently and have moved the project on to the new machine

Despite my new laptop runs 64 bits version of Windows 7, I have installed the 32bit version of Blender 2.49b because 64bit blender is kinda weak in terms of the number of things it could do

For some reason, all of the if statements which references LIST data type
(let say if ‘blahblah’ in blahblahLIST: where ‘blahblah’ is a string and blahblahLIST is the name of a list) do not work on my new laptop, nothing happen at all and no error messages neither. Otherwise, the rest of the game works fine.

I am pretty sure I haven’t touched anything after I have moved the file on to the new computer.

Does anybody knows what’s happening and how I can fix it?

p.s. I have installed python 2.6.2 (2.6.5 will not work with my Blender 2.49b)

Insert one print-statement before your if-test, so you see what the list actually contains, then check the console window for output:

print blahblahLIST
if 'blahblah' in blahblahLIST:
  do_something()

http://img405.imageshack.us/img405/7444/29116590.png

conListener.bodies is the list

:frowning: :frowning: :frowning:

Seems a bit strange to me. You could try some auxiliary tests for conListener.bodies, like

print type(conListener.bodies)
print len(conListener.bodies)
print conListener.bodies[0]

It may be some kind of strange list implementation. Or even something like

a=['1',]
print a
print '1' in a
print type(a)
a=conListener.bodies[:]
print a, len(a), type(a), "Start Walking" in a, a[0]

conListener.bodies turns out to be of the “CListValue” type
Which I guess is a bit different to just “List” :frowning: :frowning:

The really weird thing is it worked before on a different computer, I will try to get my old laptop to boot (It’s being a bit weird at the moment) later

But at the moment I am guessing it’s to do with the version of python I am using.

anyway, if you have any idea please give me an advice :slight_smile: :slight_smile:

I guess you need to do casting:

conlistenerbodies=list(conListener.bodies)
if "Start Walking" in conlistenerbodies: 
  print "working!"

or maybe

if conListener.bodies.has_key("Start Walking"):
  print "working!"

For me this seems very unpythonic programming practise, and surely there should be a direct itemgetter method for x in conListener.bodies, but somehow it is just missing.

Yep Plan A works fine but Plan B doesn’t
Well Problem solved :slight_smile: :slight_smile:
Thankyou very much for your help

Now then sigh I need to fix the rest of the game with the new solution