Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 MusicKing7 · Apr 03, 2017 at 02:05 AM · c#unity 5scripting problemsave datasaveload

[C#] Save/Load Score stays at 0 even when changed

Been having this issue for a while now and it's giving me a headache. Here's the sum of it:

https://hastebin.com/xigezexiwa.cs (Save) https://hastebin.com/anogamunix.hs (Load) https://hastebin.com/otiquguvat.cs (Full Script)

So basically I'm making a high score, the 'data.highscore' is always equal to 0. So the if statement in Save is always true. I'm trying to figure this out but anybody's help could and would be appreciated, good day ^.^!

I used some code from the Live Training Session on Data Persistence. Hope I can get this problem solved soon, it's annoying me and I can't think of another way to solve it.

Comment
Add comment · Show 6
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 Peysbubby · Apr 03, 2017 at 03:55 AM 0
Share

Hello, I don't think anyone is going to be able to help you based on what you provided. If you could please provide your full scripts (including but not limited to: where you call your Save function, and where you call your Load function) We would be able to help you a lot easier.

avatar image PizzaPie · Apr 03, 2017 at 10:01 AM 0
Share

Is Data class marked as Serializable? The code seems fine.

avatar image MusicKing7 PizzaPie · Apr 03, 2017 at 10:23 AM 0
Share

$$anonymous$$aking an edit with the full script

avatar image MusicKing7 · Apr 03, 2017 at 10:24 AM 0
Share

Also, just to note I'd rather not use PlayerPrefs for score since, as PlayerPrefs suggests, it's not a player's preference. It's a score.

avatar image Peysbubby · Apr 04, 2017 at 06:33 PM 0
Share

I've looked through your full script and everything seems to be in order, based on that script, I cannot yell you whats wrong. What I'm going to suggest is going in and "Debug.Log" ing it to death and see where its going wrong.

avatar image PizzaPie · Apr 04, 2017 at 08:52 PM 0
Share

A far fetched reason that isn't working might be that, first time you saved, you created a data file with value of 0 at the field, now every other time you try to save you keep create files with same name but windows, probably mac too, do change the name to hightierdata.dat(1) or something like that,not sure right now/ too bored to check. So when you load you load the initial file the one you created the first ever time you called the function. To check if this is the issue either go to the file folder and delete all existing hightierdata.dat files and try again. If this works let me know to tell you how to fix the code.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by dvir9299 · Apr 03, 2017 at 06:53 AM

Hi ! im also using that way to save memory ! but you should use the playerprefs to save that score , because its just a number ,nothing over that . if u want keeping using that way , you sould send the all script to so we can see where exaclly is the problem

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
0

Answer by UnityCoach · Apr 03, 2017 at 09:16 AM

 public int HighScore
 {
     get { return PlayerPrefs.GetInt ("HighScore", 0); }
     set { PlayerPrefs.SetInt ("HighScore", value); }
 }
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

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

Related Questions

Saving progress even when I quit the windows app 0 Answers

Unloading Broken Assembly | How to solve this !? 2 Answers

The spaceship acceleration script is good ? And how to use it with engine ? 0 Answers

How to make sure than one script affect the player of the specific client, and not the other 2 Answers

How to tell an operand "Once" or "Started to" 3 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