Author Topic: function not getting called  (Read 3614 times)

0 Members and 2 Guests are viewing this topic.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
function not getting called
« 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?
« Last Edit: February 19, 2013, 04:26:35 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: function not getting called
« Reply #1 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.

Some people need a high five in the face... with a chair.
~EC

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: function not getting called
« Reply #2 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.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: function not getting called
« Reply #3 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.

Some people need a high five in the face... with a chair.
~EC

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: function not getting called
« Reply #4 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.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated