No mouse input

Hi everyone,

I’m trying to set up some code that toggles a ‘build mode’ in my game (similar to that in an RTS game). I have a Boolean value which I toggle, then its true, the build mode is active, when false, it isnt.
When it is active, I want a template of the object to follow the mouse position so the player can choose where to place it, then place it with a mouse click.
I’ve got the Boolean value to toggle with a keypress, but my mouseclick wont work, it doesnt give any error messages, it just doesnt do anything. I’m sure its probably something simple but I’ve been stuck for a while on this.

Here is my code:


}//end of simple init app

 private void initKeys(){
        inputManager.addMapping("mineBM", new KeyTrigger(KeyInput.KEY_NUMPAD0));
        inputManager.addMapping("mClickLM", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(actionListener, "mineBM");
        inputManager.addListener(analogListener, "mclickLM");
 }//init keys end
 private ActionListener actionListener = new ActionListener(){
    public void onAction(String name, boolean keyPressed, float tpf){
        if (name.equals("mineBM") &&!keyPressed){
        mineBM = !mineBM;
        }//end of keypress
   }//end of on action
   };//end of actionlistener
 private AnalogListener analogListener = new AnalogListener(){
     public void onAnalog(String name, float intensity, float tpf){
     if (name.equals("mclickLM")){
         if (mineBM=true){

     }//end of mouseclick (leftbutton)
     }//end of analog
 };//end of analoglistener

}//end of simpleApplication


Thanks a lot for any help :slight_smile:

“if (mineBM=true){” is your problem. Boolean equality is checked with “==” not “=”.

If I may, I would avoid adding comments such as “//end of analog” etc because they are more harmful than helpful.
Comments should usually only be used to give non immediately evident info, otherwise it just clutters the code.

Great! thank you for that! and thanks for the advice on the code commenting :slight_smile:

You welcome :slight_smile:

@loopies said: "if (mineBM=true){" is your problem. Boolean equality is checked with "==" not "=".
You don't need to use if (mineMB == true), use if (mineMB)... mineMB is a boolean variable after all!

How come MouseButtonTrigger is analog?

Because an analog listener was added. Anything is ‘analog’ if you add an analog listener… in the sense I’m guessing you mean.