mouse sensor python

How would i make my mouse sensor activate my motion actuator?

import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = cont.sensors["Mouse"] 
mouseover = controller.sensors["Mouseover"] 
hitpos = mouseover.hitPosition

    if mouse.positive and mouseover.positive: 
        actuator = co.actuators["billy"]


cont.activate(actuator)

It did not work.Here is the error i get.

Read new prefs: C:\Users\My world\AppData\Roaming\Blender Foundation\Blender\2.6
9\config\userpref.blend
found bundled python: C:\Program Files\Blender Foundation\Blender\2.69\python
read blend: C:\Users\My world\Desktop\New blender game engine programming\sendin
g messages with python .blend
Detected GL_ARB_texture_env_combine
Detected GL_ARB_texture_cube_map
Detected GL_ARB_multitexture
Detected GL_ARB_shader_objects
Detected GL_ARB_vertex_shader
Detected GL_ARB_fragment_shader
Detected GL_ARB_vertex_program
Detected GL_ARB_depth_texture
Detected GL_EXT_separate_specular_color
Python error compiling script - object 'Cube.004', controller 'And':
  File "pop.py", line 10
    if mouse.positive and mouseover.positive:
    ^

Well, if my eyes are right, the error is not related to the problem at hand. Is there a “IndentationError: unexpected indent” message in the console?

Yes there is but i did not see it at first.

I… think you solved then? Fix the indentation and it will work. Dealing with sintax is part of the pain of programming, programming languages are very primitive tools.

No error in the console and it still is not working.Does that seem unusual to you.

 import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = cont.sensors["Mouse"] 
mouseover = controller.sensors["Mouseover"] 
hitpos = mouseover.hitPosition

if mouse.positive and mouseover.positive: 
    
        actuator = co.actuators["billy"]
cont.activate(actuator)

The cont.activate(actuator) use a string, try replace the cont.activate(actuator), with cont.activate(“Name of the actuator”)
Sorry english.

That does not work.

Well, as a matter of fact it not unusual at all to have something with no error and still not working, welcome to world of dynamic languages :D. Let’s say that the code is properly indented:

import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = cont.sensors["Mouse"]  
mouseover = controller.sensors["Mouseover"]
hitpos = mouseover.hitPosition
if mouse.positive and mouseover.positive:
    actuator = co.actuators["billy"]
    cont.activate(actuator)

It makes sense, you get it right, this should work from a code perspective. If it doesn’t you have to check the “hidden” conditions, like:

is “billy” the right name of the actuator? I mouse.positive True? Is mouseover.positive True?
If that’s true, does actuator actually do something?
Without a step debugger you have to check things with “print”, like in:

import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = cont.sensors["Mouse"]  
mouseover = controller.sensors["Mouseover"]
hitpos = mouseover.hitPosition
print("mouse.positive = ", mouse.positive)#grandpa debug method
print("mouseover.positive = ", mouseover.positive)#grandpa debug
if mouse.positive and mouseover.positive:
    actuator = co.actuators["billy"]
    print("billy actuator = ", actuator)
    cont.activate(actuator)

If the console prints:

mouse.positive = True
mouseover.positive = True
billy actuator = something that looks like an actuator

before to call an exorcist for your PC try to check if the actuator, when active, actually does what it should (by manually setting a fake, always true condition that activates it)

By the way, this kind of struggling is absolutely normal when dealing with a new API and/or tool set. Things will flow smoother as long as you keep practicing with it.

sending messing.blend (472 KB)Here’s the blend.

Yeah, the code was wrong. Names, wrong names (co, controller, cont are all supposed to be same thing, i used controller, indentation was also a bit off). Below the working code.

import bge

controller = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = controller.sensors["Mouse"] 
mouseover = controller.sensors["Mouseover"] 
hitpos = mouseover.hitPosition


if mouse.positive and mouseover.positive: 
    actuator = controller.actuators["billy"]
    controller.activate("billy")

You use Python to perform such a simple thing?

There is a nice GUI to configure that ;).