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?
$\begingroup$
$\endgroup$
2
-
$\begingroup$ Please include information about the objects, your logic editor and scripts that you are using in whatever are you doing. $\endgroup$– StrapicarusCommented Nov 14, 2017 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$– MonsterCommented Nov 14, 2017 at 7:01
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
1
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)
-
$\begingroup$ Sorry for the late response, thx you so much for this :) $\endgroup$– YasefCommented Nov 16, 2017 at 22:06