Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jul 24, 2016 at 06:57 AM by Hellium for the following reason:

This question does not respect the rules of Unity Answers : Posting about a specific compiling error or NullReferenceException

avatar image
0
Question by kilincege · Jul 24, 2016 at 06:43 AM · intconvertingstring formattingconverting-var-type-to-other-var-type

Cant convert int to string in c#

Here is my code:

 public class checklevelcheckskill : MonoBehaviour {
 
     public string PlayerSKillPointsS;
     public int RequiredSkillLevelForUpgrade;
     public int PlayerSkillPointsInInt;
 
     //BUttons and Menus
     public GameObject SkillPointsWarningMenu;
     //Written Variables
 
     // Use this for initialization
     public void Start ()
     {
         RequiredSkillLevelForUpgrade = 0;
         SkillPointsWarningMenu.active = false;
     }
     
     // Update is called once per frame
     void Update ()
     {
         PlayerPrefs.GetString("PlayerSkillPoints");
         PlayerSKillPointsS = PlayerPrefs.GetString("PlayerSkillPoints");
         PlayerSkillPointsInInt = PlayerSKillPointsS;
     }
 
 }

Im getting this error: Cannot implicitly convert type 'string' to 'int' And when I changed my script to this,

 public class checklevelcheckskill : MonoBehaviour {
 
     public string PlayerSKillPointsS;
     public int RequiredSkillLevelForUpgrade;
     public int PlayerSkillPointsInInt;
 
     //BUttons and Menus
     public GameObject SkillPointsWarningMenu;
     //Written Variables
 
     // Use this for initialization
     public void Start ()
     {
         RequiredSkillLevelForUpgrade = 0;
         SkillPointsWarningMenu.active = false;
     }
     
     // Update is called once per frame
     void Update ()
     {
         PlayerPrefs.GetString("PlayerSkillPoints");
         PlayerSKillPointsS = PlayerPrefs.GetString("PlayerSkillPoints");
         PlayerSkillPointsInInt.ToString() = PlayerSKillPointsS;
     }
 
 }
 

Now Im getting this error: The left-hand side of an assignment must be a variable, property or indexer

I just want first variable to be equal to second one. PlayerSkillPointsInInt = PlayerSKillPointsS;

Are there anybody knows how to solve this problem? Thanks For Your Help.

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

  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Jul 24, 2016 at 06:47 AM

Your title says convert int to string, which is done trivially using the ToString() method. However, your question is actually about converting string to int, which must be done slightly differently since not every string can be represented as an int. Try this :

 int.TryParse(PlayerSKillPointsS, out PlayerSkillPointsInInt);
Comment
Add comment · Show 2 · 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 Hellium · Jul 24, 2016 at 06:56 AM 1
Share

@tanoshimi : Please, don't forget the rules of Unity Answers : FAQ

For this kind of question, leave a comment in the moderation queue and reject the question right after. Unity Answers is full of off-topic questions like this one. This is a C# problem, not a Unity-related one.

avatar image tanoshimi Hellium · Jul 24, 2016 at 07:03 AM 0
Share

@Hellium - I can't leave comments on posts in the mod queue any more, and there was also a rule about not rejecting posts without an explanation :( But yeah, you're right - this one could probably have been rejected. To be fair to the OP, the code was formatted correctly, the error message was stated in full, and they had tried to make a change to fix the error themselves. And they were polite. :)

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Having a GUI text as a int 3 Answers

Getting string to int then var 1 Answer

A string converted from Json cant become "smart" and understand variables in my code, true or false? 1 Answer

String can't be converted to float or int? 1 Answer

How can I make a Dropdown option to be converted on a text to appear somewhere? 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