Change python script type to module

Hello everyone, I’ve been attempting to create a script that needs to create a python controller under game logic and change its mode to ‘MODULE’

The code I have for adding my game logic controller is:

 bpy.ops.logic.controller_add(type='PYTHON', name="GenTerrain") 

When using the info window when changing a python controller to ‘MODULE’ manually, blender shows that it is using the following command:

 bpy.context.object.mode = 'MODULE' 

When I try to use this inside my code it gives me an error stating that:

 AttributeError: bpy_struct: attribute "mode" from "Object" is read-only 

Any help would be greatly appreciated :slight_smile:

Welp after being stumped for a good 30 minutes trying to figure this out, literally the minute I posted this I solved the issue, that’s programming for you… :rolleyes:

Turns out all I needed to do was to create a variable assigned to my last created controller:

controllers =
controller = controllers[-1] 

And then use that controller so I end up with:

 controller.mode = 'MODULE' 

Next time I’ll dig around a bit harder before running off for help, it’ll save me the embarrassment of coming back 2 minutes later to post my solution :o