I have been working on a program that has an intro, but fans of the program want the ability to turn them on and off. I can turn them on and I can turn them off, but not consistently. I don’t have any problem saving the bools from the toggles in the other scripts, but this one is causing problems that I cannot seem to narrow down.
Any suggestions would be great as I am stopping for the night as I have been looking at this code for too long.
I’m actually not sure what your if checks are doing in Start. You should just check if the playerprefs returns a 0 or 1.
Honestly, I think the value of intros will always be true also. Since if the first if check, which also does an assign is false, the second one will set it to true.
But, you don’t use the value of intros anywhere except the debug messages.
So, the next thing would maybe be the IntroStop method to look into. But, you weren’t really clear on what you meant by things being inconsistent.
It always boggled me that PlayerPrefs doesnt have Get/SetBool. I abstract it away in a Storage class and avoid all the what means what after. you may want to alter the Get signature to support providing a default boolean for consistency with the PlayerPrefs, but this is what I use.
public const int FALSE_INT = 0;
public const int TRUE_INT = 1;
public static bool GetBool(string key){
return PlayerPrefs.GetInt(key, FALSE_INT) == TRUE_INT;
}
public static void SetBool(string key, bool value){
int i = value ? TRUE_INT : FALSE_INT;
PlayerPrefs.SetInt(key, i);
}
public static bool IntToBool(int i){
return (i == TRUE_INT);
}
public static int BoolToInt(bool b){
return b ? TRUE_INT : FALSE_INT;
}
}
Okay so, I was able to get something to work by creating another int and saving that to fix the bool issues. Now my issue is, I am able to disable the intro for one startup, if I do not go back into the options panel and click the toggle again, the intros will appear in the next run. I tried the code provided, thank you btw, but it had a problem with Prefs.Instance that I couldn’t seem to fix. Small video attached to see what I am seeing.
Hi. I have a settings file in my VR app but I don’t use the PlayerPrefs stuff preferring to write my own for maximum control. But I can tell you what I can see (or in one case, don’t see). Is something calling the IntroStop method because I don’t see if called here.
I have no idea what you are doing in the Update method but if it is important to keep setting your intros property repeatedly the following should do it.
private void Update()
{
intros = (value == 1);
}
.
Something similarly “odd” is going on in IntroStop BTW. You test for !disable.IsOn and set it to false or if it is on you set it to true which means the setting does not change. And if the check box is “disable” then it sounds like checking it would mean intros should be false (maybe?).
In any case it appears that if the disable check is not selected then intros should be true and the value 1 should be saved. If that logic is reversed it is easy to reverse the values but this is all that should be required.