I would like change the name of a Game Property when the game is running.
For example I have a Cube with a property called “Cube”. How can I change this name
for example when I press “1” on my keyboard to the name “Sphere”?
I hope that anybody can help with with this question.
I would like to exclude an object from being detected by a ray sensor or a near sensor.
Moreover I use a small script which tracks an object to the nearst property.
Ok, thanks for your answers. But it will be enough just to add a property and delete a property.
I look for a solution all day. Do you have an example file where a property is added and removed? I am not that good in Python and I think thats a part
of the problem.
I won’t give an example for that because what you are doing is learning it the wrong way.
but i can explain what it does
def change_property(cont):
#own short for owner, the object the script is run from
own = cont.owner
#looks at own if a property called cube is present
if 'cube' in own:
#create a property called new_property and add the value of the old cube property into it
own['new_property'] = own['cube']
#removes the cube property from own
del own['cube']
so you use a single property to track, so you alter the tracking script to get it to work with the right method.tracking to a property is good, if you delete that property, the script will give errors and stop working, because the script can’t run anymore due to the property it tracks to is removed.
And that’s why you should keep the property convert to string, and change it’s value to the object you want to track to. This also means that you need to adjust the tracking script a tiny bit.