Cannot add an actuator from a non-active controller

(Makers_F) #1

Hi! :slight_smile:
I have a problem. I was doing my first game, and so i was scripting everything inside blender. Now i decided to load the scripts from a file, so i’ve rewrited everything. After correcting same errors, i come up with this

Traceback .. in file... at line... in definition..
c.activate(over)
SystemError: Cannot add an actuator from a non-active controller..

It happens also with other c.activate…
The problem is that in the module i put many definitions, so there are some definition that aren’t always actived… Must i split the module in multiple parts, or is there a way to solve the problem?

0 Likes

(SolarLune) #2

To my knowledge, you can’t add an actuator to a non-activated controller (to a controller that isn’t on, that isn’t active through a sensor’s pulses).

0 Likes

(andrew-101) #3

As far as I know there is only one active controller at any time due to serial processing, and thats bge.logic.getCurrentController().

Are you anywhere in your code referencing a controller other than bge.logic.getCurrentController()?

0 Likes

(Monster) #4

Just to make clear:

You can’t add sensors, controllers or actuators at BGE.
The error message said “add” because internal there seems to be a list of active actuators. The message is a bit misleading.

I think it meant “activate”.
As Joeman16 and andrew-101 already said, an actuator can ONLY be activated by the currently evaluated/executed controller. If an acutator is not link to it, it can’t.

The best way is to make sure you are accessing the right actuators:


cont = getCurrentController()
actuator = cont.actuators[...]
cont.activate(actuator)

I hope it helps

0 Likes

(Makers_F) #5

yeah, i figured that “add” meant “activate” :slight_smile:
The code is something like

import GameLogic

g = GameLogic
c = g.getCurrentController()
s = g.getCurrentScene()
objlist = s.objects
o = c.owner
...
def over():
 over = c.actuators["overly scene"]
 c.activate(over)
....
def...
def...
def...

When i activate a controller that activate the definition over it gives me
over = c.actuators[“overly scene”]
KeyError: requested items “overly scene” does not exist
But it obviously exist, and is connected to the controller (that is in an active state) that run the definition( when the script wasn’t a definition in the module it worked)

If i try to change in

over = arm.actuators["overly scene"]
c.activate(over)

where arm is the object that own the actuator, it gives me
c.activate(over)
Cannot add an actuator from a non-active controller

I read my first post, and it’s not really clear.
I have(for example) a module with def1, def2, def3 and 3 controllers cont1, cont2 and cont3.

Each controller is connected with a sensor (and that gives no problems) and an actuator, and each controller is a python module controller that activate one definition.

So, when cont1 is activate, it runs def1, that activate act1… The problem is that act1 is not activate because of the previous error… Hope it’s more clear… If not, i can post the project, but the porting of the project to modules is half way, so you will get lots of other errora… :slight_smile:

0 Likes

(Monster) #6

so you running a module?

In that case it is not recommended to assign any variables with references to the current controller or object at module level (no indentation).

This is executed exactly once, by the first controller importing this module.
This would be fine as long only ONE controller is doing this.
But if another one imports this module as well the references would be to the other controller/object.

This is much different to a script. While the scripts just dies after execution, the module keeps alive in memory. Each time you reference anything from the module it is exactly the same (Python) object.

How to solve this?
as suggested use GameLogic.getCurrentController() within the function level or transfer it by function parameters.

If you use the module mode of the Python controller the first parameter of the called function is the current controller (regardless how you name the formal parameter):


def myFunc(cont):
  currentObj = cont.owner # accessing the current controller

I’m taking your code as example:

g is always right as GameLogic never changes
c is incorrect when calling any function from another controller
s is incorrect when calling any function from a controller within another scene (overlay scene)
objlist the same as s
o the same as c

BTW: on character variable names is just and does not support the readability of the code. It is recommended to use this in a very small context only (e.g. an index in a loop). Try to goes what “s” means if you have to scroll up 2 pages or more (string? stapel? shoe? scene? saturation? saturn?).

1 Like

How Do You Add Overlay Scene with Python?
(Makers_F) #7

Ok, so i have to put outside the definition what remain always constant, and inside the definition everything elso? I’ll try!! Thank you so much!!!

(yeah, i know character as variable are confounding, but i use always g =GameLogic, c=controller o =owner s=currentscene(i have a module for each main object in each scene). These are the only 4 variable with the name of a character)

0 Likes