# How can I activate an actuator if A is false and B is true?

I have two Random sensors on an object. One is triggering the spawning of an object, and the second I would like to use to spawn a second object from the same spawner. The issue is sometimes the spawn times coincide so the objects end up colliding with each other and ending up on top of each other. I would like to detect if random sensor B is true, and if so, see if random sensor A is false. If it is then proceed to spawning the object.

Can this be done using logic bricks? And if not, can Python be used?

• How about inverting the output of random sensor A, and connecting it and random sensor B to an AND controller? – X-27 Nov 8 '15 at 4:18
• Sensor A is triggering an add object actuator as well. The whole point of this is too keep them from spawning at the same time. – VRM Nov 8 '15 at 12:23

# Assumptions

You activate both randomly?

You want that only one at the time gets activated?

# Analysis

It seams you have two independent random results that both decide when a certain object gets created.

## Possible solution

How about changing the decisions? One random result decides when an object gets created and a second random result decides what object gets created.

### How to decide what object to create?

You have two (or more actuators to activate) so you need a random result that represents one of the possible actuators. The simplest representation is you number them:

1. Actuator A
2. Actuator B

This way you can use the random actuator to generate a random number between 1 and you maximum (2) to be placed in a property. With the random actuator you can decide the likelihood what actuator to activate (e.g. you want 50:50 so you use "Int Uniform"

### How to decide when to activate the actuator?

You already did that with the random sensor. It acts as "Bool Uniform" which means 50:50 chance.

### How to connect both aspects?

This example just show how to randomly generate a random object number:

Now you add the actuators dependent on the previous choice:

You check what actuator to activate either 1 or 2 and activate the actuators. Only one condition can be positive at the same time.

We do this after the random actuator completed (actuator sensor). Otherwise there can be another object after a one frame delay, which looks like it created a second object at the same time.

## Another Possible solution

You decide the what as above. You decide the when the same way. The benefit is that you get better control how to generate the wait time.

Now you get two properties:

• one with the actuator number (actuatorNumber) and
• one with the time to wait (waittime).

The timer property counts upwards so we generate negative wait times. When the wait time gets positive it is time to generate a new actuator number, new wait time and activate one of the actuators.

Interestingly the activation logic is the same as in the above solution. So I do not repeat it here.

I hope it helps

PS: I forgot to mention:

When deciding what to activate you can add "unmapped" numbers. This way it decides to activate nothing (e.g. 0=nothing, 1=Actuator A, 2=Actuator B).

• Very interesting approach! I'll see how that works, I'll accept it if it does. +1 – VRM Nov 9 '15 at 12:42
• Somehow I made the score/ammo/remaining time text disappear upon game start now . . . I don't see how it could be related but I didn't change anything else. – VRM Nov 9 '15 at 15:27

Using python you can get the status of each sensor and add any logic you want to choose which actuators get activated.

import bge

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

rnd1 = cont.sensors['Random1']
rnd2 = cont.sensors['Random2']

if rnd1.positive and not rnd2.positive:
elif rnd2.positive:


In fact you could change the first test to if rnd1.positive: as the second actuator won't get activated at the same time as the first.

All you need is the Nand controller.

It triggers the connected actuator only when:

1. One of the connected sensors is true, and
2. One of the connected sensors is false

Just plug both your random sensors in to the Nand controller.

• I don't think that will work, as if A is true and B is false it will fire as well. The reason this is an issue is because I am spawning different objects. – VRM Nov 8 '15 at 0:23