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
-1
Question by Albert-han · Jul 15, 2014 at 12:28 PM · errorunexpected

string comparisons

Hi guys, to fix my last problem i changed everything to a string but now i have a problem i cant use >, = ,>= i cant use comparisons,how do i fix this?thanks

Comment
Add comment · Show 15
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 Tehnique · Jul 15, 2014 at 12:39 PM 0
Share

Do you need to compare string lengths? If so, use String.Length.

avatar image Albert-han · Jul 15, 2014 at 12:41 PM 0
Share

i need to compare the value of the string

avatar image dsada · Jul 15, 2014 at 12:42 PM 0
Share

It depends on the language you are using

avatar image Landern · Jul 15, 2014 at 12:45 PM 0
Share

if you are using string.Compare, you should be able to evaluate equal, less, or greater from the output as str1 and str2 are compared.

 string your$$anonymous$$om = "Bobbi";
 string yourDad = "Bobby";
 
 if (string.Compare(your$$anonymous$$om, yourDad) == 0)
   Debug.Log("$$anonymous$$y $$anonymous$$om is $$anonymous$$y Dad");
 else
   Debug.Log("$$anonymous$$y $$anonymous$$om is NOT my Dad"); // <-- thats the one
 
 

if it's less than 0, in the case above, str1(yourmom) is less than str2(yourdad), greater than is just the opposite.

avatar image Landern · Jul 15, 2014 at 12:56 PM 1
Share

If your experience is an integer, then for the love of all that is natural in the world, use it(cast whatever) as an int and stop trying to work around your issues, just like the experience issues you're having from YOUR php script that you have posted twice about in the last two days.

Here: http://answers.unity3d.com/questions/748528/receiving-xp-but-not-setting-it.html And Here: http://answers.unity3d.com/questions/748068/not-receiving-exp.html

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fafase · Jul 15, 2014 at 12:43 PM

Use http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx

The result is -1, 0 or 1 depending if the first is before, same or after.

   string a = "Player1";
   string b = "Player2";
   print(String.Compare (a, b));

This will print -1 since the first is smaller than the second.

   string a = "Phil";
   string b = "Alan";
   print(String.Compare (a, b));

This will print 1 since Phil is alphabetically after Alan.

Each char is compared until there is a mismatch, the result of it defines the return value.

EDIT:

 int result = String.Compare(exp, expToLevel); 
 if( result < 0) // Not enough exp
 else if (result == 0) // Just the right amount
 else if (result > 0) // More than enough

Comment
Add comment · Show 1 · 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 15, 2014 at 02:04 PM 0
Share

How do i multiply a string?thanks

avatar image
-1

Answer by Albert-han · Jul 15, 2014 at 01:47 PM

Posting in answer to let people see the lines.

This is my script now.On line 62 i need my ExpToLevel to be a string not an int but i already set it as a ExpToLevel int.

     //public int CurLevel;
     //public int NextLevel;
     //public int ExpToLevel;
     //public int Exp;
     public int CurLevel;
     public int NextLevel;
     public int ExpToLevel;
     public string Exp;
     public static RankManager Inst;
     public int MaxLevel;
     public WeaponManager Player;
     // Use this for initialization
     void Start () {
 
         Debug.Log ("Getting xp");
         Exp = PlayerPrefs.GetString("PlayerScore");
         Debug.Log ("Got xp");
         //NextLevel = CurLevel + 1;
         Inst = this;
 
     }
 
     // Update is called once per frame
     void Update () {
         //int xp;
     //  if (int.TryParse(Exp, out xp))
         //Exp = PlayerPrefs.GetInt ("PlayerScore");
         //Debug.Log ("Update xp");
 
         if (NetworkManager.Instance.MyPlayer.PlayerName != "") 
         {
             Player = NetworkManager.Instance.MyPlayer.Manager.FirstpersonCont;
 
             foreach(Gun g in Player.Weapons)
             {
                 if(CurLevel > g.UnlockLevel)
                 {
                     g.Unlocked = true;
                 }
                 else
                 {
                     g.Unlocked = false;
                 }
                 foreach(Sight s in g.Sights)
                 {
                     if(s.UnlockKills >= g.Kills)
                     {
                         s.Unlocked = true;
                     }
                     else
                     {
                         s.Unlocked = false;
                     }
                 }
             }
     }
         if (CurLevel >= MaxLevel)
         {
             CurLevel = MaxLevel;
         }
             if (Exp >= ExpToLevel) 
             {
                 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");
                 }
 
             }
 }
 }
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 dsada · Jul 15, 2014 at 02:48 PM 1
Share

And why you need the XP to be string ins$$anonymous$$d of Int? Really dont understand.

How will you handle the situation if the player gets more xp than he needs to level up and you need to handle the rest? I see absolutely no reason to handle it as String

If you want to store the xp in playerprefs you can store integer there using SetInt and GetInt ins$$anonymous$$d of the string version

avatar image Albert-han · Jul 15, 2014 at 10:32 PM 0
Share

Because for some reason when i use it as int i cant receive xp from database.

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

26 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

Related Questions

Multiplying a string 1 Answer

Input string was not in the correct format 1 Answer

Please help get my code to work...compiler errors 2 Answers

Parsing Error : Unexpected symbol 'end of file' 2 Answers

Input string was not in the correct format 2 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