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 Punkjim420 · Aug 25, 2012 at 03:01 PM · javascriptsaveloadplayerpref

Trying to save/load game, codes doesnt do anything. not even an error.

UnityScript is my language of choice.

Im trying to write a save/load function, but when i type what ive seen everyone else type it doesnt work, no saving, no loading, it doesnt debug.log and it doesnt error. ive been thinking on this for a few hours and still dont know where to even begin. any thoughts?

and please write in a way thats easy to understand, i have a rough time understanding others. (thats why i STILL cant understand the tutorials i read) replies, especially explaining how code works should be simple or "idiot proof" if you will..

Please and thank you.

this is my code (excluding most things unrelated to the question)

I am trying to copy my variables values and paste into playerprefs i think.. and then call the values from the playerprefs later/after restarting the application. however neither happen and as i said before, no errors in the compiler.

         public var playerCurHp : float;
         public var playerMaxHp : float;
         public var playerCurMp : float;
         public var playerMaxMp : float;
         public var playerCurExp : float;
         public var playerMaxExp : float;
         public var playerLevel : float = 1;
         public var str : float = 1;
         public var atk : float = 1;
         public var def : float = 1;
         public var vit : float = 1;
         public var mag : float = 1;
         
         playerCurHp = 100;
         playerMaxHp = 100;
         playerCurMp = 100;
         playerMaxMp = 100;
         playerCurExp = 1;
         playerMaxExp = 20;
         regenTime = Time.time;
         
         DontDestroyOnLoad(this.gameObject);
 
         if(Input.GetButtonUp("Jump")){
             PlayerPrefs.SetFloat("playerLevel", playerLevel);
             PlayerPrefs.SetFloat("playerMaxExp", playerMaxExp);
             PlayerPrefs.SetFloat("playerCurExp", playerCurExp);
             PlayerPrefs.SetFloat("playerMaxHp", playerMaxHp);
             PlayerPrefs.SetFloat("playerCurHp", playerCurHp);
             PlayerPrefs.SetFloat("playerMaxMp", playerMaxMp);
             PlayerPrefs.SetFloat("playerCurMp", playerCurMp);
             Debug.Log("1");
         }
         if(Input.GetButtonUp("MiddleClick")){
             playerCurExp = PlayerPrefs.GetFloat("playerLevel");
             playerCurExp = PlayerPrefs.GetFloat("playerMaxExp");
             playerCurExp = PlayerPrefs.GetFloat("playerCurExp");
             playerCurExp = PlayerPrefs.GetFloat("playerMaxHp");
             playerCurExp = PlayerPrefs.GetFloat("playerCurHp");
             playerCurExp = PlayerPrefs.GetFloat("playerMaxMp");
             playerCurExp = PlayerPrefs.GetFloat("playerCurMp");
             Debug.Log("2");
         } 
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Screenhog · Aug 25, 2012 at 03:39 PM

Well, you have the same code twice for GetInt("PlayersCurExp"), and I don't think you're setting the correct values either. But the big problem is probably the fact that you're setting PlayersCurExp and PlayersMaxExp as Floats, and then retrieving them as Ints. If you SetFloat, you should GetFloat, not GetInt.

Comment
Add comment · Show 3 · 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 Punkjim420 · Aug 25, 2012 at 08:31 PM 0
Share

omg...wow.. ok im sorry i wasted your time like that.. it was actually very late. and i feel kinda stupid now lol. thanks for the input.. ill try again.

avatar image Punkjim420 · Aug 25, 2012 at 08:47 PM 0
Share

ok i edited the code above , now it loads my playersCurExp and players$$anonymous$$axExp it just doesnt load it correctly. ins$$anonymous$$d...i go change my Exp on purpose(to notice if it loads) then i press load after and it loads but without the previous state of exp. ins$$anonymous$$d exp just goes empty(i leveled up again). or it gives a random amount of exp. even if i saved with 80% exp on my exp bar. the level never gets loaded, nor the hp or mp, but exp does seem to change.(to not having any exp)

avatar image Screenhog · Aug 27, 2012 at 03:45 PM 0
Share

Read the last bit of code again... you're assigning playerCurExp seven times. :)

(Don't worry about it... I used to make errors like this all the time)

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

8 People are following this question.

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

Related Questions

player prefs, problem but no problem??? 1 Answer

playerprefs problem 0 Answers

Save/Load - Strange behaviour 1 Answer

Save and load data with Javascript... 0 Answers

How to load saved data from another scene? 2 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