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 16, 2014 at 01:52 PM · errorunexpected

ExpToLevel not increasing

Hi guys,i have been using this script for leveling in the game but i tried to simplify it to make it shorter then after i did that,my leveling stopped working.

NewScript:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class RankManager : MonoBehaviour {
     public int CurLevel;
     public string 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 () {
         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;
                     }
                 }
             }
         }
     }
 
     void MultiplyExperience(){
         if (CurLevel >= MaxLevel)
         {
             CurLevel = MaxLevel;
         }
 
         int Compare = string.Compare(Exp, ExpToLevel);
         Debug.Log ("Compared");
             if (Compare == 0);
             else 
             if (Compare > 0) // More than ExpToLevel
             {
             CurLevel++;
             int exptolevel =  Convert.ToInt32(ExpToLevel);
             exptolevel *= 2;
             ExpToLevel = exptolevel.ToString();
             }
 
 
                 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");
                 }
 
 }
 }

Old Script:

    //public int ExpToLevel;
     //public int Exp;
     public int CurLevel;
     public int NextLevel;
     public string ExpToLevel;
     public string Exp;
     public static RankManager Inst;
     public int MaxLevel;
     public WeaponManager Player;
     int i;
 
 
 
     // Use this for initialization
     void Start () {
 
 
         Debug.Log ("Getting xp");
         Exp = PlayerPrefs.GetString("PlayerScore");
         Debug.Log ("Got xp");
         //NextLevel = CurLevel + 1;
         Inst = this;
         if (int.TryParse(ExpToLevel, out i));
 
     }
 
 
     // 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;
         }
         //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;
             int exptolevel =  Convert.ToInt32(ExpToLevel);
             exptolevel *= 2;
             ExpToLevel = exptolevel.ToString();
 
             //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");
                 }
 
             }
 }
 }
 

ExpToLevel is not doubling when my exp is higher than it.

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 Landern · Jul 16, 2014 at 02:01 PM 4
Share

A quick comment, throughout the last couple of days and because of the free hosting/php/mysql service you use... you have created one of the nastiest kludges i've seen in a long time. You really should workout your data store issues (returning an int from mysql that is wrapped in various ad crap from the free host) and code to the actual types. You've created your own mess by trying to work around EVERYTHING ins$$anonymous$$d of doing it remotely "more correctly". Just my 2 cents.

avatar image Albert-han · Jul 16, 2014 at 02:14 PM 0
Share

Tried my best...

avatar image awest · Jul 16, 2014 at 02:42 PM 0
Share

I think it would be a lot easier to store Exp and ExpToLevel as ints.

 int Exp = int.TryParse(PlayerPrefs.GetString("PlayerScore"));

then when you save back to "PlayerScore"

 PlayerPrefs.SetString("PlayerScore", ""+Exp);          //Or
 PlayerPrefs.SetString("PlayerScore", Exp.ToString());

This allows you to work only with ints while still storing it as a string. The math should be a lot easier to work out, test, debug, etc.

0 Replies

· Add your reply
  • Sort: 

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

24 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

Related Questions

String Multiplying 1 Answer

Another error 0 Answers

Not receiving exp 1 Answer

Unexpected Token: if 2 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