Hi there!
I’m horribly stuck and have yet to find a solution, and appreciate it in advance any assistance the community can give me. Initially, the script used a list to store a class type ‘Questions’ which I am trying to create a dictionary so that I have a key->value pair. I call the dictionary in the MainController class shown below
using System.Collections.Generic;
public class MainController : MonoBehaviour
{
public Dictionary<int, Questions> GameQuestions;
functions....
}
I then later use the GameQuestions dictionary in the LoadQuestions function as shown below:
void Start()
{
//Invoke the load question coroutine
if (Mode == DownloadMode.Offline)
StartCoroutine(LoadQuestions());
else if (Mode == DownloadMode.Online)
StartCoroutine(DownlaodXML());
else
StartCoroutine(HybridLoader());
}
private IEnumerator LoadQuestions()
{
//Show the splash screen
SplashScreen.SetActive(true);
//Hide the retry button
RetrySplashButton.SetActive(false);
//Activate the splash screen loading animation and start playing it
SplashScreenLoading.gameObject.SetActive(true);
SplashScreenLoading.Play();
//load the questions from the XML
TKContainer ic = TKContainer.Load(OfflinePath);
if (AllQuestions.Count > 0)
{
AllQuestions.Clear();
}
general.load();
}
When I’m trying to call GameQuestions.Count in the LoadQuestions IEnumerator, I receive the following error.
The errror refers that I never create the GameQuestions variable, yet I have and doesn’t seem to recognize it. Visual Studios never errors that I haven’t created the variable yet, so I wouldn’t know why it isn’t being found. I at a lost and can’t seem to figure it out. It worked perfectly when it was a list, however errors as a dictionary. The only differences between the two generics is that a dictionary isn’t serializable, but I wouldn’t think at all that would cause this issue. I have made GameQuestions as a local variable and it does work when it is in the function, however I need it to be a global variable as many other functions rely on it. Once again, thank-you for your assistance and I will provide more information if you need it.
Thank-you!