No use of sensor logic bricks.

Is it possible if instead of using a Mouse sensor logic brick, I could just implement into my script. Say for example when the left mouse button is clicked I want to set test = 1 or something. I’ve tried looking around and I’ve found things like bge.types.SCA_MouseSensor and bge.logic.KX_MOUSE_BUT_LEFT but I have no idea how to use these. Thanks

import bge

keyboard = bge.logic.mouse

        print("Clicked Left Mouse Button!")

should do the trick.

import bge

mouse = bge.logic.mouse

if[] == 1:
        #this triggers once, for one tick even if the mouse is held
        print("Clicked Left Mouse Button!")

if[] == 2:
        #this triggers continually whilst the mouse is held
        print("Holding Left Mouse Button!")

if[] == 0:
        #this triggers whilst the mouse is released
        print("Mouse Button is not being pressed!")

It is possible but inefficient.

Why so? Wouldn’t it save time if I had lots of different objects which need the same set up.

And also, is it possible to with other sensors in general?

Especially this makes it more inefficient.

The sensors ensure the (Python) controller runs only if needed e.g. if the sensors deliveres new input.

You would need to run the Python controller all the time.
In most cases you just find out there is nothing to do as there is no change on the input.
And this is a waste of processing time.

The sensors do this kind of processing already and in a much more efficient way as you could do with Python.

Not running an Python controller is always better then running a Python controller (regardless what it does).

There are situation when you would a Python controller run all the time. You can use the Pulse modes of the sensors.


If You run python every tic anyway (I usually do for any main character) it is probably cheaper to us the events in python than running yet one more python script/module on another set of sensors.

If not - running python code only when needed from dedicated sensors is faster.

So basically if I want a lot of objects that use the same script, I should just go through adding all the sensors to each of them? There’s gotta be some way to copy and paste all the logic bricks to another object?

Thank you so much Monster! That will help a lot. I will take your advice into consideration