- Home /
Question by
trinitysj96 · Jan 27, 2013 at 08:08 AM ·
javascriptplayerprefsphpxp
trouble with db and playerPrefs
here is my script:
private var secretKey="RomanIsGod"; // Edit this value and make sure it's the same as the one stored on the server
var highscoreUrl="http://www.mysite.com/folder/game/file.php?";
var curExp : float;
var maxExp : float;
var level : float = 1;
var expTexture : Texture;
var w : float = 900;
var style : GUIStyle;
function Start() {
SetPlayerName = PlayerPrefs.GetString("playerName");
//style.normal.textColor = Color.yellow;
//style.fontSize = 10;
getScores(SetPlayerName);
}
function Update() {
SetPlayerName = PlayerPrefs.GetString("playerName");
getScores(SetPlayerName);
}
// Get the scores from the MySQL DB to display in a GUIText.
function getScores(SetPlayerName) {
var highscore_url;
//var highscore_url = highscoreUrl + "name=" + SetPlayerName + "";
Debug.Log (highscore_url);
gameObject.guiText.text = "";
hs_get = WWW(highscoreUrl);
yield hs_get;
if(hs_get.error) {
print("There was an error getting the high score: " + hs_get.error);
} else {
gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
Debug.Log (hs_get.text);
var getXP : int = hs_get.text.string;
curExp = getXP;
}
}
function OnGUI () {
GUI.depth = 200;
Debug.Log ("scores: " + getScores);
GUI.DrawTexture(Rect(Screen.width / 2 - 450, Screen.height - 48, w *(curExp/maxExp), 30), expTexture);
}
function waitTen()
{
yield WaitForSeconds(10);
}
the problem is here:
var highscore_url;
//var highscore_url = highscoreUrl + "name=" + SetPlayerName + "";
which is supposed to do:
GUI.DrawTexture(Rect(Screen.width / 2 - 450, Screen.height - 48, w *(curExp/maxExp), 30), expTexture);
this is the line bar that shows your current level progress in xp.
when I change the the "highscore_url" to the one that sets the "SetPlayerName" line the whole thing breaks, and I am pretty good with php.. that part of the code and the database are fine and I get the return variables that I am looking for.
I am trying to set the curExp and the maxExp which come from the database as curExp/score and maxExp/level.
what am I doing wrong?
Comment
Your answer
Follow this Question
Related Questions
Playerprefs not saving 1 Answer
How do you run multiple Playerprefs scripts (JS)? 1 Answer
UI Slider, Save Values and Change Them 0 Answers
How to save the best score 1 Answer
Highscoring and changing scripts (Java/UnityScript) 1 Answer