bool[ ] array = {PlayerPrefsX.GetBool(“string”,false )…}; making array a global Variable
however “GetInt can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.”
I’m not 100% sure what you are trying to do here with the code you posted, but if you want to save an array of data into PlayerPrefs, why not just use for loops? Use 0 as false and 1 as true for boolean.
for(int i = 0; i < arrayLength; i++)
{
PlayerPrefs.SetInt("MyBooleanName" + i, myValue);
}
This is the method I am personally using to save arrays of data into PlayerPrefs, it is simple and clean (probably not the most efficient, but hey, it works).
Please use code tags. Otherwise most of the people won’t bother trying to read the code
If you need to save an array of booleans, either try to convert them into an int (32 booleans per integer) or if you need way more, consider building a string. Do not save every single boolean as an integer.
So I appears to work well in creating the PlayerPrefs, however how can i store it into a global array now? I need a global array because when I want to reference one of the playerPrefs i pass in the value the player is on. fir example array[valuePlayerIsOn];
If you could help me trough that I think my problem will be fixed
So Thanks to everyone that tried to help! What I ended up doing was using the for loop Pinsukka gave me and when wanting to reference a player prefab Just Type PlayerPrefs.GetInt(“MyBooleanName” + reference to the number value the player is on). Since the for loop creates playerPrefabs with the name MyBooleanName0, MyBooleanName1, etc .