Hey all, I’m trying to figure this out. I have one script that handles several objects, but needs to have different outcomes depending on which object it is attached to. It checks the object’s game property to differentiate between objects. Would something like this be correct? Is this how you access the game property of an object?
if obj["BlueKart"]: #if object has "BlueKart" property
#do something that applies to blue kart
elif obj["GreenKart"]: #if object has "GreenKart" property
#do something that applies to green kart
I’m using this for the AI karts in my racing game. Instead of having a separate vehicle wrapper script for each kart, I want to have one script which changes the vehicle wrapper settings depending on the kart it’s attached to.
no, that just checks if the boolean value of the property is True.
If it doesn’t exist, it throws an error.
You should remember that object properties are stored on a dictionary
So, you can use ‘in’
if ‘BlueKart’ in obj:
…
elif ‘GreenKart’ in obj:
…
however, you could add a property: Kart, and set the value to BlueKart etc
Hmm, neither method seems to be working right, though it may be due to other complications. With the second method you suggested, does the value of the property have be in quotes? And the property must be a string property, right?