I know that maybe is a simple stupid question for some but I have a cube that is player and I copied with cylinder that is object. Cylinder has property “prop” with “1” as value. How can player at collision get the value from “prop”? If it is 1 will “do something”.
With messages or python.
look up messages. And with python:
def get_scene(scene_name):
scenes = logic.getSceneList()
scene = None
for sce in scenes:
if sce.name == scene_name:
scene = sce
if scene == None:
print('\n*** No scene found with the name: ' + str(scene_name) + ' ***\n')
else:
return scene
def get_object(scene_name, object_name):
scene = get_scene(scene_name)
object = scene.objects[object_name]
return object
def grab_property(cont):
own = cont.owner
grab_property_from = get_object('scene_name','object_name')
own['property'] = grab_property_from['a_property']
Lots of code for a simple task, but this is to make it easier to be used.
- run it from the object that needs the data
- Hook up always (collision or keyboard,etc) -> python(set to mudule) -> scriptname.grab_property
To use simply fill in the details in the script
Thank you but I forgot to mention that I need python.
Thank you.
I wasn’t very clear I want the property value from any object that I collide with with that property name. Has to be just a line of code to add into my python code.
if you are using a collision sensor, which i recommend, its pretty easy to get a list of objects colliding
for obj in sensor.hitObjectList:
prop = obj.get("prop", None)
if prop != None:
#do things with obj and prop
Thank you. And if I already collided how can I get an update when the value of property is changed?
simply have a bit of logic watching the prop for a change. im not sure what you are trying to do.
contrary to popular belief, its not bad at all to have code running all the time. whats bad is to have all code running all the time.
I don’t know how to do it.
So the property that cube is getting from cylinder is changing random, is like a sensor. So if I collide I can get the value from the collided but if it updated the colider will not be updated and I want to update it constantly by each change.