(Edit. Just in case certain people don’t know, this is in Slick2d’s library)
There doesn’t seem to be an easy way to transfer data through states without singleton.
I tried using singleton, but the class failed to ‘save’ the data when made in other states. I need to do this so I can transfer the players stats through parts of the game.
Maybe I made singleton the wrong way?
Here’s my Singleton:
package edu.bgp.global.utilities;
public class PlayerStats {
private static PlayerStats stats = null;
public String playerFirstName = "";
public String playerLastName = "";
public int playerAge = 0;
public int playerZodiac = -1;
//------First int
//0 is Bravery (Attack)
//1 is Willpower (Defense)
//2 is Agility (Evasion)
//3 is Intelligence (Magic)
//4 is Comprehension (Modifies EXP gained)
//-------Second int
//0 is the level
//1 is the EXP
//2 is the EXP next
public int playerStats[][] = new int[5][3];
public int day = 1;
public int month = 1;
public int birthday = 1;
public int birthmonth = 1;
public String timeOfDay = "Morning";
private PlayerStats(){
for (int a = 0; a < 5; a++){
playerStats[a][0] = 1;
playerStats[a][1] = 0;
playerStats[a][2] = 100;
}
}
public static PlayerStats getStats(){
if (stats == null){
stats = new PlayerStats();
}
return stats;
}
}