Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vectorizing · Oct 08, 2013 at 09:11 PM · javascript

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by meat5000 · Oct 08, 2013 at 09:46 PM

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()

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vectorizing · Oct 08, 2013 at 10:03 PM 1
Share

Well I feel really stupid, rena$$anonymous$$g the script from "PlayerPrefs" to "PlayerXP" fixed the problem, apparently you cannot have your script the same name as "PlayerPrefs" because it screws with unity. I was meaning to use OnDisable so thanks for that catch because I didnt even notice that, I appreciate your help a bunch!!

avatar image
0

Answer by Tomer-Barkan · Oct 08, 2013 at 09:56 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How i make this code in Unity Javascript 2 Answers

using Application.OpenURL for opening new tab? 2 Answers

Vehicle Won't go past 2nd gear. 1 Answer

Network Error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges