In this specific example, adrainsnetlis is correct. However, I think it’s also a good idea to look at why you thought that would work.
It seems like you’re writing code that you’ve made up, without referencing any documentation. It would be great to have such an ability when writing code, but unfortunately due to the fact that everyone has their own way of writing things, including APIs, I have to refer to documentation when looking for things that I’ve never used before.
In addition, code doesn’t just “not work”, it will (in the case of Python) throw an error message, to indicate something happened that wasn’t supposed to. There are rare occasions when the code is legal but doesn’t do what you expect, because you’ve asked it to do something slightly differently.
So, in this example, to work out why it doesn’t work.
This is the error message in the Python Console. To show the console on Windows, go to Window/Toggle System Console (in Blender). For Linux / MacOSX, launch blender from the terminal, or run the embedded console app.
This error says the following:
Python Script Error - object “Cube”, controller “Python”
Which means that the controller called “Python” on the “Cube” object was the one that failed
File “… .py”, line 7, in ender
Which means that the Python script called t.py was the script that failed, at line 7, which is in a function called “ender”.
AttributeError: “KX_RadarSensor” object has no attribute “negative”.
This means that the Python object* for the Radar sensor does not have an “attribute” (anything after a full-stop character, like sensor.positive, cont.owner, bge.logic) called “negative”. It does, however, have a positive attribute!
*NOT GameObject; In Python, every “thing” is an “object”. In this case, the radar sensor logic brick is, in Python, a KX_RadarSensor object (instance)
Most of the time, these error messages can be looked at by yourself, with no one else to help you, and solved. It will make you a better coder, and get things solved quicker.
The Python documentation is used to tell developers what API functionality is available, what it is called and where to find it. The documentation for the latest release of Blender is found here. You can also find the link by going to Help/Python API Reference (in Blender).
The BGE documentation is found in the Game Engine Modules section of the page. To find out what is available for things like sensors, you must look in the Types section (bge.types module), because all BGE “things” (sensors, objects, meshes) have a Python class/type that has attributes.
E.g the RadarSensor
Some types inherit from other types, which is indicated by the parenthesis after the type name (In this example, note the “(KX_NearSensor)” written after “KX_RadarSensor”. This means that the KX_NearSensor object is a parent of the KX_RadarSensor object. The KX_NearSensor object itself has a parent (and so on). Eventually, because the RadarSensor is a sensor, it inherits from SCA_ISensor, which doesn’t have a negative attribute.
Of course, because Sensor.positive is a Boolean object, you can get the opposite result (if it is negative), by writing “not” in front of the result.