Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Highscore table not working and I dont know where the problem may be. HELP please

Discussion in 'Scripting' started by SirMarley, Aug 20, 2014.

  1. SirMarley

    SirMarley

    Joined:
    Jul 26, 2014
    Posts:
    115
    Guys... help please...

    I don´t know where my problem may be... but everytime I try to send the data to the database, the "external controller" gives me an error and stop working and, regardless, nothing is sent...

    Can you take a look please?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameOver : MonoBehaviour {
    5.  
    6.     public string stringToEdit;
    7.     private int lSel;
    8.     public bool _pressedOk;
    9.  
    10.     public string name;
    11.     public int score;
    12.     public string[] top10Scores;
    13.     public string db_url = "http://localhost/unity_test/";
    14.    
    15.     void Start () {
    16.         lSel = PlayerPrefs.GetInt("EngSpaChi");
    17.         if (lSel == 1) stringToEdit = "Enter Your Name";
    18.         if (lSel == 2) stringToEdit = "Ingresa Tu Nombre";
    19.         if (lSel == 3) stringToEdit = "輸入你的名字";
    20.  
    21.         score = 1500;
    22.     }
    23.  
    24.     void Update () {
    25.    
    26.     }
    27.  
    28.     void OnGUI()
    29.     {
    30.         stringToEdit = GUI.TextField(new Rect(Screen.width * .2f, Screen.height * .6f, Screen.width * .2f, Screen.height * .1f), stringToEdit, 30);
    31.         if (GUI.Button(new Rect(Screen.width * .41f, Screen.height * .6f, Screen.width * .1f, Screen.height * .1f), "OK"))
    32.         {
    33.             _pressedOk = true;
    34.         }
    35.  
    36.         if (_pressedOk)
    37.         {
    38.             name = stringToEdit;
    39.             StartCoroutine(SaveScores());
    40.             _pressedOk = false;
    41.         }
    42.     }
    43.  
    44.     IEnumerator SaveScores()
    45.     {
    46.         WWWForm form = new WWWForm();
    47.  
    48.         form.AddField("newName", name);
    49.         form.AddField("newScore", score);
    50.  
    51.         WWW webRequest = new WWW(db_url + "SaveScore.php", form);
    52.  
    53.         yield return webRequest;
    54.     }
    55. }