- Home /
Best way to store RPG job experience?
Apologies if this is the incorrect place to ask this question, I am new to Unity and game development. I am making an RPG for the first time and am working on how jobs/classes work. I would like to add a system where enemies will give players "Job EXP" that will go towards their "Job Level". Each job a character holds will have 3 values: "Current Job Level", "Job Experience" and, "Job Experience Required For Next Level". I am unsure of the best way to store all this information.
Currently the solution in my mind is to have them all as separate int values. But if I decided to have, say 20 jobs available in the game, then that's 20 X 3 values - 60 different fields within my character class. With 4 party members that makes 240 fields to hold all that information. Is that too much? Does anyone have a method of storing these values that takes up less space, or makes more sense? Any help is appreciated and I can provide code if needed!
Answer by Hellium · Aug 30, 2020 at 12:10 PM
No, having 3 individual integers for each job directly stored in your Player is not a good idea.
Why don't you store the job information in its own class & create an array in your Player class?
[System.Serializable]
public class Job
{
[SerializeField] private string name;
[SerializeField] private int currentExperience;
[SerializeField] private int[] experienceTresholdsToNextLevel; // 10, 100, 1000, .... or whatever
public string Name { get { return name; } }
public int CurrentExperience { get { return currentExperience; } }
public int Level()
{
int level = 0;
while(currentExperience > experienceTresholdsToNextLevel[level])
{
level++;
}
return level;
}
}
public class Player : MonoBehaviour
{
[SerializeField]
private List<Job> jobs = new List<Job>();
public void LearnJob(Job job)
{
jobs.Add(job);
}
}
This looks like a great way to do it which I hadn't considered, and it should fit nicely into my existing code! I'll give this a shot and let you know if it all works well! Thanks very much!