Scan for a variable based upon an integer

so i am trying to make a quest system for a game and the problem currently at hand is that each one of the 60 quests has a save data variable. what i need to do is make it so the script checks a variable without running if statements 60 times.

if(questvar == 1){
status = Savedata.Quest1;
}

if(questvar == 2){
status = Savedata.Quest2;
}

if(questvar == 3){
status = Savedata.Quest3;
}

if(questvar == 4){
status = Savedata.Quest4;
}

//and continues all the way to 60

if there is already an answer out there please point me to it,
if not any help on this would be appreciated
-T.D.M.3

I think what your are trying to do can be simply accomplished as follows:

  1. Each Quest script should have a public variable “Status”, which is what you want to access, and has been assumed to be int in this example (but it can be anything you want). The “Status” variable replaces the QuestX variables.
  2. All Quest scripts should be held (referenced) by the current script, meaning the one that has all the if statements.

Here’s the code:

using System.Collections.Generic; //needed to use List

//Drag-n-Drop Quests in Inspector
//Or use GetComponent to populate the Quests List (Quests can then be made private)
public List<Quest> Quests;  //hold all Quests in a List. 
private int status;


//Call this method when you want to get the status
void CheckQuestStatus(int QuestNumber)
{
	int questIndex = QuestNumber - 1; //First List index = 0
	
	if (questIndex >= 0)
	{
		this.status = Quests[questIndex].Status;
	}
	else
	{
		Debug.Log("Quest Number must be greater than 0");
	}
	
}

What are you exactly trying to do? I think you can greatly improve your design by getting rid of the integer “questvar”.

In what form is your SaveData.QuestX?

Generally you should store all of your quests in either a Dictionary, so that you can retrieve a quest by its Dictionary key (a string name) or in a List, if they are consecutive. Then you could have a method “GetNextQuest” which just takes the current quest and returns the next item in the list.