Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When I was going to create another state I had an error. This is my code:

   public static final int play2 = 3;

and

public Game(String gamename){

      this.addState(new mission(play2));
   }

and

public void initStatesList(GameContainer gc) throws SlickException{
      this.getState(play2).init(gc, this);

   }

I have an error in the addState. above the above code. I don't know where is the problem. But if you want the whole code it is here: package javagame;

import org.newdawn.slick.*;

import org.newdawn.slick.state.*;

public class Game extends StateBasedGame{

   public static final String gamename = "NET FRONT";
   public static final int menu = 0;
   public static final int play = 1;
   public static final int train = 2;
   public static final int play2 = 3;

   public Game(String gamename){
      super(gamename);
      this.addState(new Menu(menu));
      this.addState(new Play(play));
      this.addState(new train(train));
      this.addState(new mission(play2));
   }

   public void initStatesList(GameContainer gc) throws SlickException{
      this.getState(menu).init(gc, this);
      this.getState(play).init(gc, this);
      this.getState(train).init(gc, this);
      this.enterState(menu);
      this.getState(play2).init(gc, this);

   }

   public static void main(String[] args) {

      try{
          AppGameContainer app =new AppGameContainer(new Game(gamename));
          app.setDisplayMode(1500, 1000, false);
          app.start();
      }catch(SlickException e){
         e.printStackTrace();
      }
   }

}
//SYSTEM NETWORKS(C) 2012 NET FRONT

ERROR:

The method addState(GameState) in the type StateBasedGame is not applicable for the arguments (mission)
share|improve this question
Can you share the error here? Then we will able to help you. – Mahbubur R Aaman Sep 25 '12 at 9:37
5  
@SystemNetworks. You have 10 questions and still only 1 rep. Many of your questions are too localized or show lack of research. This question isn't any different. You're just showing us your code and telling us the error your getting. You need to invest some time in learning to use the debugger and reading documentation. Additionally, you've received answers/comments to a few of your questions and haven't accepted/responded to most. – Byte56 Sep 25 '12 at 13:44
It seems that you do not extend from the BasicGameState class in your mission class. See my edited answer. – tom van green Sep 25 '12 at 14:51

closed as too localized by Byte56, Jonathan Hobbs, Yannbane, Jari Komppa, Josh Petrie Oct 4 '12 at 16:02

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Edit: Based on the error message I assume, that your class mission is not extending from BasicGameState or GameState, but the addState method expects a GameState object (or an object derived from GameState). Extend BasicGameState in mission and it should work.

Old Answer:

Move the code from the constructor into the init method. The states should be added during init. You can also remove the calls to the states init method, as this is already done by the StateBasedGame class and therefore you would initialize each state twice.

Your init method should look like this:

public void initStatesList(GameContainer gc) throws SlickException{
  this.addState(new Menu(menu));
  this.addState(new Play(play));
  this.addState(new train(train));
  this.addState(new mission(play2));
  this.enterState(play2);
}
share|improve this answer
It didnt work for me! – SystemNetworks Sep 25 '12 at 11:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.