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 02:00 AM · errornotunexpectedsetting

Cant Receive Exp

Hi guys,i havee a script that takes xp from my database and just sets it on the player

 public void GetXp(string User)
     {
         Debug.Log ("GetXp Successful");
         WWWForm www = new WWWForm ();
         www.AddField ("user", User);
         WWW w = new WWW ("http://www.reactivestudios.comuv.com/Exp.php",www);
         StartCoroutine (Xp(w));
 
     }
     IEnumerator Xp(WWW w)
     {
         yield return w;
         if (w.error == null)
         {
                 Debug.Log (w.text);
                 Debug.Log ("Working Stats");
                 int i;
                 if (int.TryParse(w.text, out i))
                 PlayerPrefs.SetInt ("xp",i);
             Debug.Log("Set int xp");
             }
         else
         {
             Debug.Log ("Parsing Failed");
         }
     }

but i have a problem.I received the xp from the internet because i (debug.log) it ("Set int xp")line 20)and it sets it as an int(line 19 i think so).But then my other script (rank manager) takes the int and set it as exp(line 9 and 53)But the one on line (53) does not (debug.log)"rankmanager getting int"line 54) and i think that is causing the problem that i cant set my exp but i dont have any idea why this is happening.please help.thanks

     public int Exp;
     public static RankManager Inst;
     public int MaxLevel;
     public WeaponManager Player;
     // Use this for initialization
     void Start () {
 
         Debug.Log ("Getting xp");
         Exp = PlayerPrefs.GetInt ("xp");
         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;
                     }
                 }
             }
     }
         if (CurLevel < MaxLevel)
         {
             if (Exp >= ExpToLevel) 
             {
                 CurLevel++;
                 ExpToLevel *= 2;
                 if(Network.peerType != NetworkPeerType.Disconnected)
                     NetworkManager.Instance.MyPlayer.Manager.networkView.RPC("UpdateRank",RPCMode.All,CurLevel);
                 PlayerPrefs.GetInt("xp" + NetworkManager.Instance.PlayerName, Exp);
                 Debug.Log("RankManager Getting Int");
             }
         }
 }
 }

I hope you guys understand my question.Thanks :D

Comment
Add comment · Show 1
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 07:57 AM 0
Share

anybody willing to lend a hand here?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gjf · Jul 15, 2014 at 09:06 AM

line 53 is trying to get a different PlayerPref.

you've set it to "xp", but trying to get "xp" + NetworkManager.Instance.PlayerName which probably doesn't exist.

Comment
Add comment · Show 7 · 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 10:44 AM 0
Share

i dont think it is beacuse of that.I found something new.The set int is not actually setting anything either that or it cant getint from another script.Any idea?

avatar image Albert-han · Jul 15, 2014 at 11:01 AM 0
Share

I created another project just to test and it worked i dont know why i did set int and in another script get int.

avatar image gjf · Jul 15, 2014 at 11:09 AM 0
Share

what messages are displayed?

Debug.Log("Set int xp"); is executed whether the SetInt occurs or not because the previous '`if`' only executes the code on line 19 so you can't tell whether the int was set or not.

first, you should fix that.

also, think about when these scripts will be executed - if you don't have anything else setting up the "xp" int then it might not exist by the time Update() in the second script runs.

maybe try the alternate syntax with a default value...

avatar image Albert-han · Jul 15, 2014 at 11:26 AM 0
Share

i check something and the getint "xp" is getting 0.why is it getting 0 when set it to w.text out i in the other script.

avatar image gjf · Jul 15, 2014 at 11:34 AM 0
Share

what's the value of w.text? add a Debug.Log()

if you tell me a valid user for GetXp then i could try it myself... trying to help you

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

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

Switching between two weapons 1 Answer

WeaponScript not working 0 Answers

Multiplying a string 1 Answer

Compiled Game Crashing 1 Answer

About www.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