How do I efficiently code an achievements system?

0 favourites
  • 2 posts
From the Asset Store
Implement a customizable array-based achievement system with the fully-commented template.
  • 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.


    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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)