How do I efficiently code an achievements system?

Get help using Construct 2

Post » Mon Apr 24, 2017 10:57 pm

Having never done an achievements system before, I could do it in what is certainly a very inefficient way. I bet that someone out there knows of a convenient and code-efficient way!

My current system is as follows: I have 16 achievements, each with an icon that is gray if not completed or colored if completed.

In an event, once the player's save file is loaded, I have 16 separate conditions checking to see if each achievement is met. For example, collect X amount of money or play X amount of hours. Once triggered, the achievement sprites have a variable for "IsComplete" that gets turned "true." Any icon that is "IsComplete" changes to its 2nd frame, which is a colored version of the sprite.

EXAMPLE:
If sAchievementIcon.Number = 1 & Hours played >= 50, set "IsComplete" to "true."
If sAchievementIcon.IsComplete = "true," set frame from 0 to 1.


I suppose this could be done in an array, but the conditions for the achievements are not always as simple as "this value is greater than or equal to X." Some achievements involve doing multiple things at once (having a powerup while killing a certain enemy, completing two stages in under 20 seconds, etc), so putting the condition for each achievement in the array is probably more complex than it's worth. So my solution is simply to have 16 separate events that check each time the player's save data is loaded, which seems really inefficient, but is much more user friendly than trying to force unique achievement conditions into arrays.

Thank you!
B
24
S
6
G
1
Posts: 47
Reputation: 1,894

Post » Tue Apr 25, 2017 4:18 am

Your conditions don't go in the array (or dictionary would probably be more appropriate). The array/dictionary only serves as a replacement for instance variables to store if an achievement was completed or not.

Your condition and event to trigger an achievement should be one time only, and when it triggers it will set the corresponding array/dictionary value and that value can be saved forever. You'll still have an event for each accident, which specifies all the conditions to reach the achievement. The state/animation frame of your achievement​ sprites should be based off of your stored value, and you can loop through all of those in a single event to set them.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 27 guests