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 Dok101 · Jun 21, 2014 at 07:54 AM · errorvariablegetcomponentplayerprefs

Player Prefs, Adding Two Variables

Hi I'm using Player Prefs to set two of my variables. I took the code from the Unity Scripting API. While I'm able to set my variable to a specific number using the PlayerPrefs.SetInt function I can't add two variables.

My code is

 using UnityEngine;
 using System.Collections;
 
 public class League : MonoBehaviour {
     int DivisionNumber;
     int RacesLeft;
     int Points;
     int PointsForWin;
     int PointsForPrize;
     int PointsForOut;
     int MoneyForWin;
     int MoneyForPrize;
     int MoneyForOut;
     int FameForWin;
     int FameForPrize;
     int FameForOut;
 
     Career_Variables career = GameObject.Find("career_Variables").GetComponent<Career_Variables>();
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
 
     if (RacesLeft >= 0 && Points >= PointsForWin)
         {
             DivisionNumber --;
             PlayerPrefs.SetInt("Career_Variables.Fame", Career_Variables.Fame + FameForWin);
             PlayerPrefs.SetInt("Career_Variables.Money", Career_Variables.Money + FameForWin);
 
 
         }
     }
 }
 

This is all I got to in my code before it started generating errors. It shows the errors "error CS1503: Argument #2' cannot convert object' expression to type int'" error CS1502: The best overloaded method match for UnityEngine.PlayerPrefs.SetInt(string, int)' has some invalid arguments and error CS1503: Argument #2' cannot convert object' expression to type `int'.

However when I change it from Career_Variables.Money + MoneyForWin/Career_Variables.Fame + FameForWin those 3 errors go away. This leads me to wonder if you can add two variables with the Player Prefs because I copied and pasted the GetComponent part of the code from another file which showed no error and the gameobject name was the same.

Any help will be appreciated

Thank you in advance

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 dsada · Jun 21, 2014 at 08:42 AM

You can not store 2 variables for one key. You need different key for every value. But the error was not about this. The problem was that you argument's type was Object and you have to add Int. that could be easily solved by Convert.ToInt32(argument)

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

[SOLVED] Help with PlayerPrefs.SetInt 1 Answer

Problem calling variable across scripts (Closed) 1 Answer

'name' is not a member of Object (js) 1 Answer

Is it possible to set variables for classes? 2 Answers

Get Component 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