Just wondering how this works.
If I have lets say a collision sensor in the logic bricks and I call the hitObject property of the object. When I print it, it shows correctly in my terminal. But when I compare it to a string it fails. It prints like a sting in the terminal, but not in actual code.
Here is an example:
I have a sensor named “check_ground” attached to a player. Ground plane is named “ground”
import bge
cont = bge.logic.getCurrentController()
sen_ground = cont.sensors["check_ground"]
print(sen_ground.hitObject #prints right, which is the ground game object
if sen_ground.hitObject == "ground":
#fails
if str(sen_ground.hitObject) == "ground":
#works
This also happens for other things such as scene.active_camera.
Why do I have to explicitly use str() for it to work? Is there some property I’m missing? I tried looking through the API, but didn’t find anything. I know it’s all objects, but shouldn’t this be a string var in the class sensors?
Just wondering though, not too important; don’t want ugly code and all.
Also, does this forum have code tag language highlighting? I tried [code=python] but didn’t work.