How to save answer strings displayed using Random.Range and link to achievements

Hi, I’ve been trying to find a solution for this but am stuck, so any advice is really appreciated.

Right now, I have a list that is used to display strings in the list at random to the user, using Random.Range. However, those answers are not recorded or saved, so the user has no way of knowing how many of these answers they have unlocked.

This is what I have right now:

List<string> allLocations = new List<string>();

        allLocations.Insert(0, "Answer 1");
        allLocations.Insert(1, "Answer 2");
        allLocations.Insert(2, "Answer 3");
   
 // Display random answer from list

        string displayAnswer = allLocations[Random.Range(0, allLocations.Count)];

I would like to implement a way to record each displayed string if hasn’t been shown to the user before, and sort the string in a list (or more suitable option) according to different categories.

E.g if either of the strings"Answer 1" or “Answer 2” are displayed and it has not been shown to the user before, it will be recorded and count as one answer unlocked in Category A of the achievements. If the string “Answer 3” is displayed to the user for the first time, it will count as one answer unlocked in Category B.

Ideally I would be able to sort these unlocked answer strings, so that the user can see how many of the answers they have unlocked in each category. There are 101 strings of these unlocked answers which are broken down into 10 categories for the achievements.

How do I implement this and make the record of the strings previously displayed to the user accessible to a script displaying achievements? I read that JSON data serialization is better for this than PlayerPrefs, but I am unsure how to implement this.

Thank you! I apologize in advance if this is a stupid question; I’m really new to Unity and C#.

Good day.

Then the best way i think is to create another array or list with the same length. It can be a int array or string array.

In this new array you store the category of each element of the answers array. If answers[4] is displayed, then store answcategor[4] = "displayede!

I mean each answer have its own information in this new array. You only need to read/write the status in this new array.

Bye!

I suggest that you change your answer list from a string list to something like this:

[System.Serializable] //This allow us to tweak the values in the inspector
    public class Answer {
          public string text;
          public string category; //maybe should be an enum? I don't know the structure you have, but 
                                  //could be a good idea to do something like that.
          public bool unlocked;
    }    
    //Then your list
    List<Answer> answers //...

This will allow you to filter the list, sort it or do whatever using the data in the list element.