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 eeveelution8 · Aug 14, 2014 at 05:30 AM · playerprefsintvaluestore

Weapon store using playerprefs does not retain stored information.

I'musing playerprefs to store and int value under the name of 'wep1', and have it initially set to 0. when purchasing the gun, the int value should become 1. The point of the shop is to allow the user to switch between guns as they choose in the store after a one time purchase, because if the int value in the playerprefs is supposed to be initially purchased if the 'wep1' value is set to one.

The problem is that it doesn't seem to be rewriting the valueto tell the playerprefs that the value is now 1, resulting in the gun having to be rebought over and over again, which is problematic.

 var gun : String;
 
 var purchased : boolean = false;
 var cost : int = 0;
 
 var money : int = 0;
 
 var ID : int;
 
 function Update(){
 
 money = PlayerPrefs.GetInt("$$$");
 
 }
 
 function OnMouseDown(){
 if(purchased == false){
     if(PlayerPrefs.GetInt("$$$") >= cost){
         money -= cost;
         PlayerPrefs.SetInt("$$$", money);
         purchased = true;
             if(ID == 1){
             PlayerPrefs.SetInt("wep1", 1);
             }
     }
                     if(purchased == true){
                         PlayerPrefs.SetString("PRI", gun);
                     }
 }
 }
 
 function start(){
 
             if(ID == 1){
             if(PlayerPrefs.GetInt("wep1") == 1){
             purchased = true;
             }}
 
 }


This is the reduced script (As the game has 27 total weapons), I'm wondering if anyone can tell me what is causing the error.

Comment
Add comment · Show 3
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 yoyo · Aug 14, 2014 at 05:35 AM 1
Share

"$$$" may not be a valid name for a player preference value, you might want to call it "bank" or similar. Not sure if this is your problem. Are you sure the program gets to the line where it sets the "wep1" value? Try putting a Debug.Log message to make sure.

avatar image eeveelution8 · Aug 14, 2014 at 05:42 AM 0
Share

I'll get back on that in a sec,

avatar image eeveelution8 · Aug 14, 2014 at 05:46 AM 0
Share

Figured out what the problem was, but upvoting your comment for being helpful too.

1 Reply

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

Answer by eeveelution8 · Aug 14, 2014 at 05:47 AM

The start function is labeled as,

 function start(){

should be

 function Start(){
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

22 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

Related Questions

[PlayerPrefsSet...] VS [var=...] at every value update 0 Answers

Saving an int via PlayerPrefs... 2 Answers

How do Generate Random Unique int ? 1 Answer

How to return to a value used before? (C#) 1 Answer

How can i save a int for multiple texture. Please Read. 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