@SwathedOrange
I think I understand what you want. Here is what I would do
Create a new class of Question
public class Question
{
public string description;
public int type;
}
I would create a list of that Question class
public List<Question> questions = new List<Question>();
Populate that list however you want, personally I would use a CSV in resources so I could edit the CSV and the questions would be updated.
To select a random question I would write a function to return a random question based on the type needed. Using Linq to get a question (Note you’ll need using System.Linq;)
public Question GetQuestion(int type)
{
List<Question> tempList = (from x in questions where x.type == type select x).ToList();
return tempList[Random.Range(0, tempList.Count)];
}
There are a number of benefits to using this, it moves the questions into a external file for easier management, it allows you to add new fields to a question without a clunky string. It also allows for language translation in the external file if you wanted to take the game to other countries.
As an example for expansion I added the ASKED flag.
public class Question
{
public string description;
public int type;
public bool asked = false;
}
Using the new asked bool you can return questions that haven’t yet been asked
List<Question> tempList = (from x in questions where x.type == type && !x.asked select x).ToList();
Its worth noting that that could lead to a list without a selection question due to all questions could have been asked, so you will have to make sure you handle that situation
Something like this, when all questions have been asked I reset all questions of that type
public Question GetQuestion(int type)
{
List<Question> tempList = (from x in questions where x.type == type &&!x.asked select x).ToList();
if(tempList.Count == 0)
{
ResetAllQuestions(type);
tempList = (from x in questions where x.type == type && !x.asked select x).ToList();
}
Question selectedQuestion = tempList[Random.Range(0, tempList.Count)];
selectedQuestion.asked = true;
return selectedQuestion;
}
public void ResetAllQuestions(int type)
{
foreach (var question in (from x in questions where x.type== type select x).ToList())
{
question.asked = false;
}
}
Hope that helps? I haven’t tested any of this but should work
Thanks
Mike