"key not in list" error

I have a script that uses rayCastTo to get the name of an object, puts the name in a string property on the owner object, then uses gl.getCurrentScene().objects[own[‘prop’]] to get the object. I’m storing it in a property instead of just using gl.getCurrentScene().objects[own.rayCastTo(e1,5.0,"")] to get the object because the object wont always get hit by the ray.
If I use this code I get the error “KeyError: “CList[key]: ‘s1.036’ key not in list””, where ‘s1.036’ is the object hit by the ray and stored in the property. If I enter s1.036 directly into the property and get rid of the rayCastTo code, it works fine. I can’t figure out why I get this error when the properties seem to be the same either way. All help is appreciated, Thank you.

2.5 or 2.49b?

If 2.49b, maybe because “OB” is not in front of the name.

If 2.5, please post a .blend :slight_smile: Just make a simple example.

2.53, I’ll post an example in the morning.

If you have the reference to the KX_GameObject stored already there is no need to call the above code. Just take the reference from the property.

I’m pretty sure that .objects (which is a list) does not accept object references as index. It is a list and needs int or (strange enough) string.

Keep in mind if you do print() on an object and you get the same output, it does not mean it is the same object or even the same object type.
The string represantation of an KX_GameObject is the name (as string).
While the string representation of an string is the string itself.

Thank you monster, I didn’t realize that when I stored a KX_GameObject in a string property it stored the reference, I thought it only stored the name as a string. Thank you again, you have made my life alot easier.