mouse sensor and state actuator with python problem

This code shows no error in the console but it won’t switch states.How can I fix this?

import bge
bge.render.showMouse(1)
controller = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mace = controller.sensors["Mace"] 
maceover = controller.sensors["Maceover"] 
hitpos = maceover.hitPosition
 
if mace.positive and maceover.positive:  
    
 
        print ("true")
        controller.owner.color = [1.0, 0.0,0.0,1.0]

else:    
        print ("false")
        controller.owner.color = [0.0, 1.0,0.0,1.0]
if mace.positive and maceover.positive:  

  controller = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
act = controller.actuators["storp"]

group = act.mask
act.mask = 2
                   
             


You mean neither of “true” or “false” is printed?

Fix indentations and is calling “mouse” “mace” intentional? Throws me off all the time.

It prints true or false.I am trying to get it to switch states.Calling mouse mace is intentional because i have more than one python code that is similar.Because i copy and paste then modify them.That was the only way I know of to get it to work.

It prints true or false.I am trying to get it to switch states.

And where is the state you need switched?


act = controller.actuators["storp"]
group = act.mask
act.mask = 2

This one? You can put it in the same if statement as the above. If it doesn’t work then you need to debug these lines alone. Have you activated the actuator?

 controller.activate(act) 

I’m not an expert on SCA nor do I wish to be but I bet someone can help you with it. Perhaps you should at least verify the state after you try to change it and it doesn’t apparently change.

Calling mouse mace is intentional because i have more than one python code that is similar.Because i copy and paste then modify them.That was the only way I know of to get it to work.

How each script refers to stuff is only relevant to that text block at the max. But they are also relevant to a single function at best if you don’t pass them. The SCA names are only relevant to the python controller they link to. You shouldn’t really just go renaming everything to something that can’t be understood just to be safe. Makes it hard for other people to see what you are doing to help you.

Indeed you need to activate the actuator to make it run.

You do not need a separate Python controller. A simple AND controller will be sufficient (and faster).

BTW:
bge.render.showMouse(1)

should not be part of that code.
A) because you need that just once
B) it has nothing to do with your code.

Better use the configuration switch at the properties panel or if you need it dynamically execute a Python controller that switches the cursor and only the cursor.

Hint: There is no need to define the attributes controller and scene twice ;).

 act = controller.actuators["storp"]
group = act.mask
act.mask = 2

How do you debug those lines alone Kheetor?

No error in the console and still does’nt switch states.

 import bge
controller = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mace = controller.sensors["Mace"] 
maceover = controller.sensors["Maceover"] 
hitpos = maceover.hitPosition
 
if mace.positive and maceover.positive:  
act = controller.actuators["storp"]
controller.activate(act)
group = act.mask
act.mask = 2
    
 
        print ("true")
        controller.owner.color = [1.0, 0.0,0.0,1.0]
else:    
        print ("false")
        controller.owner.color = [0.0, 1.0,0.0,1.0]

Still not indented properly and with the names like that and double defining things. It’s a nightmare reading that code.


import bge

controller = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
mouse = controller.sensors["Mouse"] #proper name
mouseOver = controller.sensors["MouseOver"]  #proper name
hitpos = mouseover.hitPosition #proper name, this line does nothing useful

if mouse.positive and mouseover.positive: #why do you check for both
    storp = controller.actuators["storp"] #what is storp, one of your renames again, lets call it that anyway
    #group = storp.mask #this line does nothing useful
    storp.mask = 2 #proper name, indentation
    controller.activate(storp) #activate the actuator AFTER you set the parameters
    print ("Mouse is moving and over something")
    controller.owner.color = [1.0, 0.0,0.0,1.0]
else:    
    print ("No mouse movement or no object under mouse")
    controller.owner.color = [0.0, 1.0,0.0,1.0]

Have you studied this? http://www.blender.org/documentation/blender_python_api_2_69_1/bge.types.KX_StateActuator.html

Because looks like you aren’t setting the operation type at all and chances are you don’t understand how to properly express bundle of groups in bits either although for 2 it should matter.

You can directly switch states:


owner.state = 2 # which is 2^1 -> state3 == 4;  state4 == 8; ...

or you activate the actuator as mentioned earlier:


controller.activate("storp")

better avoid re-configuring the actuator. It is possible but might lead to confusion.

No i did not see that Kheetor.I found some code in the search and modified it by placing it together with some other code i found on Tutorials for Blender 3D and the Blender Blender 3D Game Engine websight.That is the websight i was telling other people about.