Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: ben_g on February 19, 2013, 04:26:19 pm

Title: function not getting called
Post by: ben_g on February 19, 2013, 04:26:19 pm
I have a strange problem in my current code: When I call Controls.requestKeyChange from MenuController.changeControls, it just seems to return from changeControls.

My code:

MenuController.java:
Code: [Select]
public class MenuController extends AbstractAppState implements ScreenController{
    //...
    public void changeControls(String s){
        ControlsButton1.setText("Press any button...");
        System.out.println("changeControls in MenuController called (Action: "+Controls.Action.values()[Integer.parseInt(s)]+" )");
        Controls.requestKeyChange(Controls.Action.values()[Integer.parseInt(s)], app.getInputManager(), new Runnable() {
            public void run() {
                ControlsButton1.setText(Controls.keyName);
            }
        });
    }
}

Controls.java:
Code: [Select]
public class Controls implements ActionListener{
 
    //...
    public static void requestKeyChange(Action action,InputManager im, Runnable executeWhenDone){
       
        System.out.println("requestKeyChange called (Arguments: "+action+", "+im+", "+executeWhenDone);
       
        r = executeWhenDone;
        removeControls(im);
        setupKeyNames();
       
        for(int i=0; i<keyCodes.size(); i++){
            im.addMapping(keyNames.get(i), keyboard.get(i) ? new KeyTrigger(keyCodes.get(i)) : new MouseButtonTrigger(keyCodes.get(i)));
        }
       
        System.out.println(im.toString());
       
        changingControls = true;
    }
}

Console output:
Code: [Select]
//...
changeControls in MenuController called (Action: moveUp )
BUILD SUCCESSFUL (total time: 20 seconds)

Does anyone know why this happens?
Title: Re: function not getting called
Post by: ElementCoder on February 20, 2013, 03:24:05 pm
I think you do need an instance of Controls for this to work. I've had a similar problem once, but I can't remember how it got fixed since I accidentally my harddrive.
Title: Re: function not getting called
Post by: ben_g on February 20, 2013, 03:53:45 pm
This got solved in an other forum which is specialized in java and the game engine I'm using. It turns out that there was an error, but that code that is called from GUI events doesn't print the errors in the console.

Anyway, thanks for your help.
Title: Re: function not getting called
Post by: ElementCoder on February 21, 2013, 02:41:43 am
Ok, what game engine are you using? I'm planning on a game too and am currently messing around with JMonkeyEngine.
Title: Re: function not getting called
Post by: ben_g on February 21, 2013, 02:42:56 pm
I'm using jMonkeyEngine as well. It's a very decent game engine in terms of performance. It's build-in features are a bit limited, but it's easy to extend the available ones. So if you want a good performance and don't mind having to code a lot yourself, it's a good engine for you.