So I'm making a project where the user can choose between four characters to play from a menu screen. If I want their selection to create a player actor in the first world that is of the character they chose, and for that character to stay the same as they move between levels, how would I do that? I have a separate object storing information such as the character type, but whenever I try to move between levels, I just end up getting a NullPointerException.
The object storing info:
The method of player character movement between worlds:
The object used to allow movement between worlds:
The switch statement for the first world that makes the desired character based on input:
Sorry if this is a lot, but any and all help is appreciated!
public class Information
{
private CheckL1 KL1;
public Hero hero;
public int heroName;
public Information()
{
heroName = KL1.check();
}
/**
* Act - do whatever the Information wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
public int getHero()
{
return heroName;
} private void progress()
{
if(isTouching(CheckL1.class))
{
if(info.getHero() == 0)
Greenfoot.setWorld(new L2(0));
if(info.getHero() == 1)
Greenfoot.setWorld(new L2(1));
if(info.getHero() == 2)
Greenfoot.setWorld(new L2(2));
if(info.getHero() == 3)
Greenfoot.setWorld(new L2(3));
}
}public class CheckL1 extends Actor
{
public int ero;
public CheckL1(int parEro)
{
ero = parEro;
}
/**
* Act - do whatever the CheckL1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
public int check()
{
return ero;
}
} switch(hero)
{
case 0: addObject(fighter, 25, 20); break;
case 1: addObject(mage, 25, 20); break;
case 2: addObject(soldier, 25, 20); break;
case 3: addObject(thief, 25, 20); break;
}
