0
$\begingroup$

I have a button that should make things appear and and disappear in the script. However, the actuators that make the other object disappear are on the other object.

Normally, to actuate things we cal the code something along the lines:

cont = bge.logic.getCurrentController()
button = cont.owner

However, I clearly need the controller for the other object (or at least I think I do.)

I try the following code:

label = scene.objects['Text.001'] # our aptly named explanation text
labelcont = label.controllers

for obj in labelcont:
    print("object")
print(lablecont)

"Object" never prints, suggesting to me that there is nothing in the KX_PythonSeq object that is returned by .controllers.

I also tried to use labelcont[0], and well, that returned index out of bounds.

How can I get the controller for a different object?

$\endgroup$
1
$\begingroup$

Internals

A controller is not supposed to access the internals of another object. This leads to hard to investigate dependencies and should be avoided. The BGE supports you be not allowing this.

Communication

The requester object can communicate with the serving object that it active/deactivates the actuators by itself. The serving object decides how to do that.

Example: A selection object marks selected object by setting a property at the selected object.

The selected objects play an action when the property is set/not set.

The selection object does not know how the select an object but does not care how it reacts on it. The selected object does not care how it was selected, but knows what to do in this case.

  • Selection operation and Selection presentation are separated
  • One selection object is performing the selection operations
  • Each selectable object can perform individual selection presentation.
  • The game designer defines the interface between selection object and selectable objects.

Passive object

The slave object can be a passive object (no own behavior towards the current aspect). The master object performs all operations on the slaves. The build-in logic bricks do support this behavior.

Example: A selection object adds marker objects (halo) to selected objects.

  • Selectable objects do not need own selection presentation logic.
  • The selection presentation has to be exactly the same on all objects.
  • The game designer defines the interface between selection object and selectable objects.
$\endgroup$

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.