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
1
Question by Jason Hamilton · Mar 08, 2011 at 08:35 AM · javascriptplayerprefshighscores

How can I store highscores in PlayerPrefs?

Hey, Id like to do a local highscores for my game, so I intend to use PlayerPrefs. I have absolutely no idea where to start, I suppose how to enter your name at the end??? anyways, the size of thing Id be looking for is top 5 scores with name next to them, can someone help me with this? and explanation would be great and snippets of code (not the whole thing I want to learn it not copy! :D) would be much appreciated, thankyou.

Im using javascript or unity-script whatever its called. :)

Comment
Add comment · Show 1
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 Statement · Mar 08, 2011 at 01:55 PM 2
Share

I think it's officially called JavaScript but commonly called UnityScript, since Unitys JavaScript isn't like the web JavaScript. To resolve the ambiguity it's often called UnityScript. I might be wrong on this, but that's the impression I got reading other answers and comments.

3 Replies

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

Answer by Statement · Mar 08, 2011 at 01:38 PM

If you know you will be using 5 players;

PlayerPrefs.GetString("RecordName0", String.Empty); PlayerPrefs.GetInt("RecordScore0", -1);

PlayerPrefs.GetString("RecordName1", String.Empty); PlayerPrefs.GetInt("RecordScore1", -1);

PlayerPrefs.GetString("RecordName2", String.Empty); PlayerPrefs.GetInt("RecordScore2", -1);

PlayerPrefs.GetString("RecordName3", String.Empty); PlayerPrefs.GetInt("RecordScore3", -1);

PlayerPrefs.GetString("RecordName4", String.Empty); PlayerPrefs.GetInt("RecordScore4", -1);

The keys could be formatted String.Format("RecordName{0}", recordIndex); and String.Format("RecordScore{0}", recordIndex);.

Then you could provide methods similar to:

function GetScore(recordIndex : int) : int { var key = String.Format("RecordScore{0}", recordIndex); return PlayerPrefs.GetInt(key, -1); }

function SetScore(recordIndex : int, score : int) { var key = String.Format("RecordScore{0}", recordIndex); PlayerPrefs.SetInt(key, score); }

function GetName(recordIndex : int) : String { var key = String.Format("RecordName{0}", recordIndex); return PlayerPrefs.GetString(key, String.Empty); }

function SetName(recordIndex : int, name : String) { var key = String.Format("RecordScore{0}", recordIndex); PlayerPrefs.SetString(key, name); }

Then you can get the values like:

var topName = GetName(0);
var topScore = GetScore(0);

With some tinkering about I am sure you can make better, higher level methods like:

function SetRecord(score : int, name : String)
{
    // Puts score and name to highscore, pushing worse score off the top 5.
    // You wanted to figure out some stuff yourself :)
    // But a tip is that you'd use the previous Get/Set methods.
}
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 berting01 · Feb 20, 2012 at 09:20 PM 1
Share

may I ask, if you use player pref, where does the value being saved ?

avatar image Statement · Mar 27, 2012 at 03:22 PM 0
Share

Read here.

avatar image Eric5h5 · Mar 27, 2012 at 04:22 PM 0
Share

Using ArrayPrefs2 would be a lot simpler.

avatar image
2

Answer by GameGuy · Mar 08, 2011 at 12:40 PM

You asked exactly the same here ! Whats wrong with the answer you accepted ?

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
avatar image
1

Answer by Unamine · Mar 08, 2011 at 11:17 AM

There is a super tutorial of a full RPG Burg Zerg Arcade, which teaches that part very well, but is in C #, there is only you adapt to JavaScript, the Internet has some tutorials on how to do it ... Good Luck!

Link: http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial

  1. Unity3D Tutorial - PlayerPrefs 1 / x
  2. Unity3D Tutorial - PlayerPrefs 2 / x
  3. Unity3D Tutorial - PlayerPrefs 3 / x
  4. Unity3D Tutorial - PlayerPrefs 4 / x
  5. Unity3D Tutorial - PlayerPrefs 5 / x
  6. Unity3D Tutorial - PlayerPrefs 6 / x
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

1 Person is following this question.

avatar image

Related Questions

How would I transfer these into PlayerPrefs? 0 Answers

Highscoring and changing scripts (Java/UnityScript) 1 Answer

High Score with player prefs confusion (JAVA) 0 Answers

Is there a decent tutorial for a local high score table (android)? 1 Answer

HighScore Manage Using PlayerPrefs 1 Answer


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