Best practice for tracking unlocks

Hi everyone, I’m in the process of creating a system that keeps track of my player unlocks. Right now I’m focusing on map unlocks, but later I’ll reuse the code to track available ships, upgrades and color schemes.

My maps have the following variables:

  • Map Name
  • Map Description
  • Is Map Unlocked?
  • Map Bronze/Silver/Gold Score requirements

Right now I have 2 maps, so I have the variables above x2. This is not optimal, and later on I plan to have more maps. I can use a data table and aggregate them into a single variable, but I cannot edit that in runtime so when player hits Map_01’s Bronze score requirement, I can’t set Map_02 to be unlocked. Instead I have to do:

  • Get current level name, switch on string depending on the map, and then check if the current score meets one of the unlock requirements. In my example the current level is map_01.

  • IF map02 is not unlocked AND current score is >= map01_bronze THEN set map02 unlocked.

When finishing/quitting a level or relaunching the game, it loads the save slot and when I hit my level select it reads those variables to populate the map description and enable the button that allows you to proceed to the game if you have unlocked the selected map.

What are some best practices for handling player unlocks? Because right now I’m using multiple variables and I have a strong feeling I should be using arrays.