So I am making a quest system, and I want to randomly choose a quest, but i dont want it to choose the same one again. Here is the piece on code for the string. I cant find any good answer. This is a more simple line of code.
string[] QuestChoose = new string[] {"Quest1", "Quest2", "Quest3"};
CodePudding user response:
convert to List and Operate this list
CodePudding user response:
3 methods come to mind:
- Convert to a List and call
Remove()
. - Write null into the array after having read the quest and when selecting a quest, always search for the next suggestion if null was selected.
- Keep a separate data structure like a
HashSet<int>
where you add the index in the array whenever a quest has been used. Then check for Contains on your ID when selecting.