Gee, Thanks
OH!
Oh. Oh. Derp.
Order of calls! That is the issue here. What is happening, my fine friend is this:
- MyGame Constructor is entered.
- Game Constructor is entered.
- Game initializer is called.
- MyGame.setup is called.
- MyGame.setup exits.
- Game Constructor exits.
- MyGame initialized is called.
Before anything except declaration (Not assignment) happens, the super class’s constructor is called. After that returns, the assignment is allowed to happen.
Just the proof~
public abstract class Game
{
public Game()
{
System.out.println("Got here: Game");
setup(); //If you call this method here, It will only initialize the variables to their default value
}
protected void setup()
{
}
}
public class MyGame extends Game {
private String initializerTest = "MyGame!";
private boolean useShaderPipeline = true;
public MyGame() {
System.out.println("Got here: MyGame");
System.out.println(initializerTest);
}
protected void setup() {
System.out.println(initializerTest); // Prints false
initializerTest = "SetUp!";
System.out.println(initializerTest); // Prints true
}
public static void main(String args[]) {
new MyGame();
}
}
Outputs
Got here: Game
null
SetUp!
Got here: MyGame
MyGame!
@UprightPath
Ah. Jesus. That fits perfectly with my test class. It calls setup in the constructor as well.
Er, does it? More askin’ ‘cause for some reason I didn’t see a post by you with code in here. Heh. Sorry if it seemed like I was thunder stealin’ or anything.
Either that, or I misunderstood what you just said. I don’t know which and should probably go to sleep then. Hah!
Derrrrrrrrppppppp. That was a significant issue, as my whole game ran in the constructor like:
setup();
run();
exit();
But it’s fixed now, with adding a simple start() method. Thank you everyone for helping me.