1 decade ago by peepli
Hello everyone,
I am trying to create a simple achievements system for our upcoming game. But I need help from the community regarding the design
The system is pretty simple. We have a core mechanic in our game where we throw questions to the players and they have to answer them. Each player has to first register at the start of the game. In the back end, we have a database that dynamically creates players ID on registration. In our players database there is a separate data structure called questionsSolved for each player with their specific ID which again dynamically stores all the questions that specific player solves each time.
So we are building an achievement system around this mechanic of questions solved. For now we have not really decided what kind of achievements we want to implement but some examples would be "An achievement for first three questions solved", "An achievement to solve the hardest question", "An achievement to solve question no 4,7 and 15" assuming we have around 40-50 questions in our entire game but hopefully you get the picture of where we are heading.
So my question would be how do I go about an implement a system which tracks all the different kinds of achievements.
For now I have created an Entity called Achievements. I am not sure if I should use a normal class or an Entity for now. Maybe it should be a class as its not visible or interactive in any way in our game. It just runs all the time and checks if certain achievements were met and if an achievement gets met it just throws a pop up telling "achievement 1 is unlocked" or " Ach 2 is unlocked " or watever. For now let's just say I have an Achievements Entity. So in the initial stage we want to be able to check at least 2 achievements for play test.
I think I need two functions -> checkAchievements() which runs on every update to check if a certain achievement is met. From inside this function if a certain achievement is met, I call triggerAchievements(achID) which has a switch case and spawns a specific achievement pop up for that achID.
The issue I feel is the optimization. Here are a few problems I feel I need to address but I don't know how!
1. Calling and checking the database on every update for the problems solved by a player is a big overhead I feel. This is done inside the checkAchievements() function on every update.
2. Also for every achievement, the conditions would be different for that achievement to be met. If I have say 100 achievements in my game, how do I go about and implement the different checks for each achievement. For now in my checkAchievements() function, I call various other functions that check for specific achievements. Meaning if I have 100 achievements in my game I have to write down 100 different functions in my checkAchievements() function which is a lot!
How do I address the above two problems? Is there a better design structure?
I would be really really grateful if anyone with experience in this domain could provide me some help as I am relatively new to this type of class design or could throw a simple skeleton code of how I can structure my Achievements class.
Thank you!
I am trying to create a simple achievements system for our upcoming game. But I need help from the community regarding the design
The system is pretty simple. We have a core mechanic in our game where we throw questions to the players and they have to answer them. Each player has to first register at the start of the game. In the back end, we have a database that dynamically creates players ID on registration. In our players database there is a separate data structure called questionsSolved for each player with their specific ID which again dynamically stores all the questions that specific player solves each time.
So we are building an achievement system around this mechanic of questions solved. For now we have not really decided what kind of achievements we want to implement but some examples would be "An achievement for first three questions solved", "An achievement to solve the hardest question", "An achievement to solve question no 4,7 and 15" assuming we have around 40-50 questions in our entire game but hopefully you get the picture of where we are heading.
So my question would be how do I go about an implement a system which tracks all the different kinds of achievements.
For now I have created an Entity called Achievements. I am not sure if I should use a normal class or an Entity for now. Maybe it should be a class as its not visible or interactive in any way in our game. It just runs all the time and checks if certain achievements were met and if an achievement gets met it just throws a pop up telling "achievement 1 is unlocked" or " Ach 2 is unlocked " or watever. For now let's just say I have an Achievements Entity. So in the initial stage we want to be able to check at least 2 achievements for play test.
I think I need two functions -> checkAchievements() which runs on every update to check if a certain achievement is met. From inside this function if a certain achievement is met, I call triggerAchievements(achID) which has a switch case and spawns a specific achievement pop up for that achID.
The issue I feel is the optimization. Here are a few problems I feel I need to address but I don't know how!
1. Calling and checking the database on every update for the problems solved by a player is a big overhead I feel. This is done inside the checkAchievements() function on every update.
2. Also for every achievement, the conditions would be different for that achievement to be met. If I have say 100 achievements in my game, how do I go about and implement the different checks for each achievement. For now in my checkAchievements() function, I call various other functions that check for specific achievements. Meaning if I have 100 achievements in my game I have to write down 100 different functions in my checkAchievements() function which is a lot!
How do I address the above two problems? Is there a better design structure?
I would be really really grateful if anyone with experience in this domain could provide me some help as I am relatively new to this type of class design or could throw a simple skeleton code of how I can structure my Achievements class.
Thank you!