0
$\begingroup$

I am trying to make the sensors and actuators work in the script with scene objects but they only work with the main object, how can i make them work with scene objects on the script?

$\endgroup$
  • $\begingroup$ Please include information about the objects, your logic editor and scripts that you are using in whatever are you doing. $\endgroup$ – Strapicarus Nov 14 '17 at 0:45
  • $\begingroup$ Just for info: There is no "main" object. Python code gets executed by the "current controller". A controller is owned by an object (often referred as owner). A controller is connected to several sensors and actuators. Each sensor and each actuator is owned by an object (not necessarily the same object as the owner of the others). This is fixed as you can't change that while the game is running. But what the sensors detect is not fixed. This is recalculated at each single frame and can be read from the sensor e.g. via hitObjectLists(). $\endgroup$ – Monster Nov 14 '17 at 7:01
0
$\begingroup$

Logic bricks are attached to a single object. You can use message actuators and sensors to get an object to respond to another objects sensor.

Using a python controller it is possible to access other objects in the scene.

# Loop through all other objects in the scene
sce = bge.logic.getCurrentScene()
print("Scene Objects:", sce.name)
for ob in sce.objects:
    print("   ", ob.name, ob.worldPosition)
$\endgroup$
  • $\begingroup$ Sorry for the late response, thx you so much for this :) $\endgroup$ – Yasef Nov 16 '17 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.