I want to reverse a sensor (like pressing the invert button) however using sensor.negative doesn’t seem to work even with negative triggering on the sensor. The console returns that the keyboard sensor does not have the attribute ‘negative’.
How can I invert the input of a sensor without joining a second sensor to the python script?
Thanks
Goran
(Goran)
August 28, 2014, 2:08am
2
When a controller receives a “negative pulse”, the script runs, but sensor.positive evaluates to False, so:
sensor_negative = not sensor.positive
Also,
sensor.invert = True
will essentially press the invert button.
also, to add:
sensor.positive is a boolean, so you can check it for a negative pulse with “sensor.positive == False”
Monster
(Monster)
August 28, 2014, 2:32pm
6
It makes not much sense to check a boolean value to get another boolean value. “not sensor.positive” is the way to go.
sdfgeoff
(sdfgeoff)
August 28, 2014, 7:11pm
7
I personally find
if sensor.positive == False
easier to read, simply because my computer-science-confused brain doesn’t like having if statements simply with a value in them. I also use:
if sensor.positive == True
For the same reason, just seems more, well, consistent to me.
sdfgeoff:
I personally find
if sensor.positive == False
easier to read, simply because my computer-science-confused brain doesn’t like having if statements simply with a value in them. I also use:
if sensor.positive == True
For the same reason, just seems more, well, consistent to me.
I agree, that looks better.
Monster
(Monster)
August 28, 2014, 7:33pm
9
It is similar to write x=y1 + n 0. It is not wrong, but it adds additional operations without effecting the result.
You can read about the “if”-statement in PEP#008.