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 Albert-han · Jul 16, 2014 at 09:42 AM · errorunexpected

String Multiplying

Hi guys i have a problem.I have set all some of my int into string to work with another script(only chance for the script to work) and now i cant multiply the value of that string so i converted the involved one into a int and found another way.

I need to change that int into a string for that function only and change it back when its done.Then i cant multiply it however i want.

 if (CurLevel >= MaxLevel)
         {
             CurLevel = MaxLevel;
         }
         int ExpToLevel : String;
         ExpToLevel = ExpToLevel.ToString();
         int result = string.Compare(Exp, ExpToLevel);
         if (result == 0);
             else if (result > 0) // More than enough
             {
                 CurLevel++;
                 NextLevel = CurLevel + 1;
             //ExpToLevel *= 2;
                 
                 if(Network.peerType != NetworkPeerType.Disconnected)
                 {
                     NetworkManager.Instance.MyPlayer.Manager.networkView.RPC("UpdateRank",RPCMode.All,CurLevel);
                     PlayerPrefs.GetString("PlayerScore" + NetworkManager.Instance.PlayerName, Exp);
                     Debug.Log("RankManager Getting Int");
                 }
 
             }
 }
 }


I need the (//ExpToLevel to be an int on line 13) but need it to be string on line (7) if i dont convert it to string my other scripts wont work because i tried int and dint work.Here's my other thread (http://answers.unity3d.com/questions/748068/not-receiving-exp.html).thanks

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
1

Answer by dsada · Jul 16, 2014 at 10:20 AM

As I wrote in your previous discussion you dont need your ExpToLevel variable to be string. Make it and Integer. You cannot make math operation with strings its not what it made for.

 int difference = ExptToLevel - Exp;
 
 if(difference <= 0) //more than enough or just enough
 {
    ++CurLevel; //increase level
    Exp = difference //add the rest. It will be 0 if he     collected just enogh exp
 }

This is an obvious thing to use Integer and not string

Comment
Add comment · Show 13 · 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 Albert-han · Jul 16, 2014 at 10:32 AM 0
Share

$$anonymous$$y exp needs to be a string unless my other script wont even receive the exp from database so i need to compare a sting to an int but i dont think it works that way so i converted both of them to strings to be compared and now i just cant multiply my string to go to next level.I thought of a way but i dont know if it is possible. I need Exptolevel(default in script) to be an int but when i need to compare it i change (exptolevel) to a string (temporarily)to compare with exp (string).

avatar image fafase · Jul 16, 2014 at 10:36 AM 3
Share

So, convert it into an int, do the math and put it back into string.

  int expInt = Convert.ToInt32(Exp);
  expInt *= value;
  Exp = expInt.ToString();

You cannot do arithmetic on string, just like you cannot multiply your first name times carrot.

avatar image Albert-han · Jul 16, 2014 at 10:56 AM 0
Share

Ok thanks for the explanation so it should. Convert it to an int from string, $$anonymous$$ultiply it with the value, Change it to a string back?

If i add

  int result = string.Compare(Exp, ExpToLevel);
         if (result == 0);
             else if (result > 0) // $$anonymous$$ore than enough

Will it work because i only need it to times the value when the exp is higher than exptolevel.

avatar image fafase · Jul 16, 2014 at 11:06 AM 1
Share
 void $$anonymous$$ultiplyExperience(){
     int result = string.Compare(Exp, ExpToLevel);
     if (result > 0){
         int expInt = Convert.ToInt32(Exp);
         expInt *= value;
         Exp = expInt.ToString();
     }
 }

avatar image Albert-han · Jul 16, 2014 at 12:30 PM 0
Share

i get this Assets/Scripts/Player/Rank$$anonymous$$anager.cs(76,43): error CS0103: The name `Convert' does not exist in the current context

Show more comments

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

23 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

Related Questions

Another error 0 Answers

Unexpected Token: if 2 Answers

Not receiving exp 1 Answer

ExpToLevel not increasing 0 Answers

unexpected Token error 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