- Home /
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
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.
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?
I created another project just to test and it worked i dont know why i did set int and in another script get int.
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...
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.
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
Your answer
Follow this Question
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