I’m trying to make a game in which you need to enter a code to get items you want. I have all the codes in a SQL table on my localhost and I’m using WWW and PHP to reach it. I’m also using String.Compare to compare a string received from the PHP script to a word or phrase. The errorMsg variable changes the value of a GUI Label which displays when the variable currentWindow is equal to Window.Failed. Here’s the function that controls that:
function RegisterItem(code : String) {
registerURL = registerURL + "code=" + WWW.EscapeURL(code) + "&version=" + game.version;
// Post the URL to the site and create a download object to get the result.
var code_post = WWW(registerURL);
currentWindow = Window.Downloading;
yield code_post; // Wait until the download is done
if(code_post.error) {
errorMsg = code_post.error;
currentWindow = Window.NoConnection;
} else {
if(String.Compare(code_post.text, "Used", true) > 0){
errorMsg = "It seems that this code has already been used...";
currentWindow = Window.Failed;
Debug.Log(code_post.text);
} else if(String.Compare(code_post.text, "No code", true) > 0){
errorMsg = "This code is not in our database.";
currentWindow = Window.Failed;
Debug.Log(code_post.text);
} else if(String.Compare(code_post.text, "Version", true) > 0){
errorMsg = "Download the latest version to register this item.";
currentWindow = Window.Failed;
Debug.Log(code_post.text);
} else if(PlayerPrefs.HasKey(code_post.text)) {
errorMsg = "It seems that you already own this item.";
currentWindow = Window.Failed;
Debug.Log(code_post.text);
} else {
game.item = code_post.text;
game.items.Push(game.item);
currentWindow = Window.CodeSuccess;
}
}
}
I have the Debug Log print out what the value of code_post.text is to see what it is. When I test run the game and use a fake code I entered into the SQL table, I see that in the Debug Log, it prints out “Version”, yet the GUI Label shows the phrase I put if code_post.text is equal to “Used”. It doesn’t seem to be a problem with the PHP script (although it shouldn’t be saying that the version is wrong, but I’m not focused on that right now). What could possibly be the problem?