I am using states to set the speed output of different truck upgrade levels and engine upgrade levels. Everything is working fine, except that I need five states just like this one with slightly different values for the motion actuators. Is there any way to copy all the logic bricks from one state into a different state? State

( Ctrl+C and Ctrl+V doesn't work.)


1 Answer 1


You could use a python script to create as many logic bricks as you want.

First I create the single UP sensor, I use the length of the sensor array to get the last one created and store that in up_sens then set a few properties.

For the speed sensors we want 5 sensors with varying values so we can loop through the values and create each one, we keep track of these in a list for later. Then we do a similar loop for direction, using a list of keys instead of numbers.

We finish off with two loops that lets us create a motion actuator and controller for each combination of speed and direction, with the up always included and using link() to join each of them together.

import bpy

obj_sensors = bpy.data.objects['VehicleLogicCube'].game.sensors
obj_controllers = bpy.data.objects['VehicleLogicCube'].game.controllers
obj_actuators = bpy.data.objects['VehicleLogicCube'].game.actuators

up_sens = obj_sensors[len(obj_sensors)-1]
up_sens.name = 'UP=1'
up_sens.property = 'up'
up_sens.evaluation_type = 'PROPEQUAL'
up_sens.value = str(1)
up_sens.show_expanded = False

# create speed sensors
sp_sens = []
for sp in range(5):
    sp_sens[sp].name = 'Speed='+str(sp+1)
    sp_sens[sp].property = 'Speed'
    sp_sens[sp].evaluation_type = 'PROPEQUAL'
    sp_sens[sp].value = str(sp+1)
    sp_sens[sp].show_expanded = False

# create direction sensors
dir_sens = []
for dk in ['W','S','A','D']:
    dir_sens[len(dir_sens)-1].name = dk
    dir_sens[len(dir_sens)-1].key = dk
    dir_sens[len(dir_sens)-1].show_expanded = False

# create motion actuators
m_idx = 0
for sp in range(5):
    for dk in range(4):
        and_cont = obj_controllers[len(obj_controllers)-1]
        and_cont.show_expanded = False

        m_idx += 1
        nact = obj_actuators[len(obj_actuators)-1]
        nact.show_expanded = False
        # create action here or create before starting script
        nact.action = bpy.data.actions['Motion'+str(m_idx)]


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.