3
$\begingroup$

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.)

$\endgroup$

1 Answer 1

2
$\begingroup$

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

bpy.ops.logic.sensor_add(type='PROPERTY')
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):
    bpy.ops.logic.sensor_add(type='PROPERTY')
    sp_sens.append(obj_sensors[len(obj_sensors)-1])
    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']:
    bpy.ops.logic.sensor_add(type='KEYBOARD')
    dir_sens.append(obj_sensors[len(obj_sensors)-1])
    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):
        bpy.ops.logic.controller_add(type="LOGIC_AND")
        and_cont = obj_controllers[len(obj_controllers)-1]
        and_cont.show_expanded = False

        m_idx += 1
        bpy.ops.logic.actuator_add(type='ACTION')
        nact = obj_actuators[len(obj_actuators)-1]
        nact.show_expanded = False
        # create action here or create before starting script
        bpy.data.actions.new(name='Motion'+str(m_idx))
        bpy.data.actions['Motion'+str(m_idx)].use_fake_user=True
        nact.action = bpy.data.actions['Motion'+str(m_idx)]

        nact.link(and_cont)
        up_sens.link(and_cont)
        sp_sens[sp].link(and_cont)
        dir_sens[dk].link(and_cont)
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .