Multiple Sensors

A little question for the project I’m still working on, is it possible to have multiple conditions that must be satisfied before a python script is activated?

Cause at the moment I’m having trouble doing this, I cannot get the python script to be activated if both left mouse button is clicked and the mouse is moved over an object… If I remove one of them, the script is activated.

In other words: I want to achieve that the cursor is on a specific object before the ‘user’ clicks. So that, if a certain button is pointed at, and then also clicked on -> the python script is activated.

In the file is the current sensor situation.


Yes, it is completely possible. Are you a Python programmer?

If so, you would just do this:

if sens1.positive and sens2.positive:


if sens1.positive:
if sens2.positive:

Any combination really. sens1 and sens2 would be predefined variables.

The method you suggested doesn’t seem to make any difference… I’ve included the .blend file, the function is implemented (or tried to :p) only for Trillen (Aan / Uit)

Translated : On / Off (Trillen = Buzz)

I use the following code, which doesn’t produce any error:

import GameLogic
import cPickle

cont = GameLogic.getCurrentController()
sensor2 = cont.sensors["sensor2"]
sensor = cont.sensors["sensor1"]

if sensor.isPositive and sensor2.isPositive:
    LGOK = GameLogic.getCurrentScene().objects["OBTrilAanOK"]
    LGOK.worldPosition = [2.3,2.0,-0.14]
    LMOK = GameLogic.getCurrentScene().objects["OBTrilUitOK"]
    LMOK.worldPosition = [2.3,0.9,0.14]

GameLogic.globalDict = {}
GameLogic.globalDict['trilaan'] = "false"
GameLogic.globalDict['triluit'] = "true"

g = open("/tmp/insteltril.dat", "w")
cPickle.dump(GameLogic.globalDict, g)


MenuMatch.blend (601 KB)

Thats because you are using “isPositive” instead of “positive” like in my example. “isPositive” is a function while “positive” is a property"; “isPositive” is also deprecated.

OMG :o That was really stupid from me :slight_smile: But anyway, thanks BIG time for the quick response :cool:

Just to contribute to other people with similar problems, here another time the blend file:

Notice: The data are also written to a file; further processing of the input therefore is possible


MenuMatch.blend (706 KB)

Hey just a quick question, where can i find a list of all these new functions that blender 2.5 replaced? cause at the moment none of my old scrips will work and the console doesn’t give enough info to upgrade them…

Not for a while my friend. Blender 2.5’s official API won’t be done until the official release.

It is the Blender 2.49b APIexcluding the deprevated functions.


… is it possible to have multiple conditions that must be satisfied before a python script is activated?

Just to make it clear - the answer is: No, it is not possible.
Why: A controller (regardless of its type) gets activated when any connected sensor sends a pulse (True or False does not matter). See Sensors: A word on Pulses.

I think your question was: “How to make sure that my code is executed under certain conditions only?” Sunjay03 gave you the answer an that. No need to do it again.

By the way: isPositive is not the same as isPositive()