PlayerPrefs.GetInt Error MissingMethodException

I have been messing with this for way to long, I’m not sure what the deal is maybe someone can help. Here is my script:

var CurrentXP : int;
var SaveCurrentXP : int;

function Start () 
{
	CurrentXP = PlayerPrefs.GetInt("Current XP");
}

function Update () 
{
	SaveCurrentXP = CurrentXP;
	CurrentXP += 1;
	
	if (Input.GetKeyDown(KeyCode.P))
	{
		Debug.Log("Current XP: " + CurrentXP + "." + "Saving Current XP");
		PlayerPrefs.SetInt("CurrentXP", SaveCurrentXP);
	}
}

function OnDisbale()
{
	PlayerPrefs.SetInt("Current XP", SaveCurrentXP);
}

Basically for testing purposes I want it to save and load an integer. this interger changes every second, and I can press “P” to save it, also pressing P prints it in the log so I know that its working.

However when I start the game in the editor, I am presented with this error:

MissingMethodException: PlayerPrefs.SetInt
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey14.<>m__7 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
PlayerPrefs.Start () (at Assets/Scripts/JavaScript/PlayerPrefs.js:6)

I’ve tried researching this problem and cannot find anything.

I have successfully used PlayerPrefs in C# (I’m using javascript this time around) on a game I made a while ago. I am looking at it as a reference and nothing is helping.

Any help is greatly appreciated.

Thanks!

Some places you put a space in “Current XP” sometimes not. Make sure to get the string exactly right.

Try in your Start() routine:

if(PlayerPrefs.HasKey("CurrentXP"))
{
      CurrentXP = PlayerPrefs.GetInt("Current XP");
}

Also I assume you were trying to use OnDisable()

Since JavaScript is not really type safe, you’re probably at some point calling the PlayerPrefs.SetInt() method with a null or incorrect data type, my guess would be SaveCurrentXP.

Try checking that CurrentXp is an int before running the SetInt() command:

if (Object.prototype.toString.call(SaveCurrentXP) == Object.prototype.toString.call(1)) {
    PlayerPrefs.SetInt("Current XP", SaveCurrentXP);
} else {
    Debug.Log("Incorrect data type: " + Object.prototype.toString.call(SaveCurrentXP));
}

Another option would be your typo with “Current XP”, in one instance (line 17) you’re missing a space between the “Current” and the “XP”.

Good luck.